Skip to content

[Kotlin] Add incremental K2 graph snapshots - #1006

Draft
samchon wants to merge 25 commits into
scip-code:mainfrom
samchon:feat/kotlin-graph-snapshots
Draft

[Kotlin] Add incremental K2 graph snapshots#1006
samchon wants to merge 25 commits into
scip-code:mainfrom
samchon:feat/kotlin-graph-snapshots

Conversation

@samchon

@samchon samchon commented Sep 4, 2026

Copy link
Copy Markdown

Adds an opt-in Kotlin/JVM K2 graph export path for samchon/compiler-knowledge-graph#76.\n\n- attaches to ordinary Kotlin Gradle compilation tasks without clean or duplicate compilation\n- publishes content-addressed per-target generations behind an atomic build manifest\n- preserves Gradle incremental compilation, classpath snapshots, daemon, build cache, and configuration cache\n- emits declaration, relationship, diagnostic, origin, and unresolved-dispatch facts\n- fails closed on Kotlin Gradle Plugin versions other than 2.3.20 and on unsupported multiplatform builds\n- captures Kotlin JSON build reports, including non-incremental reasons\n\nFocused verification:\n- KotlinGraphTest\n- KotlinGraphGradleBuildToolTest (initial/no-op/edit/failure/recovery/create/delete, cache reuse, version mismatch, multiplatform refusal)\n\nThis is a draft integration branch pinned by the downstream campaign; it is not proposed for merge until the upstream shape and release strategy are agreed.

nicolas-guichard and others added 25 commits July 7, 2026 13:23
This goes one bit further than a3eb2f2 and doesn't even try to set
project repositories when settings repositories are set.

This prevents the build from failing on projects that set repositories
in Settings but don't set FAIL_ON_PROJECT_REPOS, such as the KotlinConf
app.
For scip-kotlinc:

* CheckerContext.containingFile was renamed to containingFileSymbol.

* FirCallableSymbol<*>.directOverriddenSymbolsSafe now takes context by
  context parameter.

* FirCallableSymbol.callableId was made nullable and is replaced by
  FirCallableSymbol.callableIdForRendering for rendering purpose.

* Anonymous objects are now considered as locals.

Ported from mozsearch/semanticdb-kotlinc@3f47564
This will allow us to distinguish between method and constructors, and
get better kind information for locals.

Ported from mozsearch/semanticdb-kotlinc@6affaf7
This changes the symbols of getters and setters to be `x.get().` and
`x.set().` instead of `getX().` and `setX().`.

Ported from mozsearch/semanticdb-kotlinc@7b4bd70
This will allow us to get the parent symbol for locals as well.
For non-locals, it should be equal to the current symbol minus the last
segment.

Ported from mozsearch/semanticdb-kotlinc@63c9b65
This should reduce memory usage a bit and avoids lots of “given file is
not under the sourceroot” clutter when running the tests.

Ported from https://github.com//mozsearch/semanticdb-kotlinc/commit/65b1898de26c02929f1fbd445a3c9c92e8fd3bab
scip-kotlinc changes:

getContainingSymbol was moved from o.j.k.fir.analysis.checkers to
org.jetbrains.kotlin.fir.resolve.

CompilerPluginRegistrar now has a virtual pluginId which must match the
CommandLineProcessor.

Ported from mozsearch/semanticdb-kotlinc@cde86db
- Remove unnecessary cast to FirClass in SymbolsCache (FirClassSymbol.fir already returns FirClass)
- Use parameterless toClassLikeSymbol() overload in AnalyzerCheckers
- Remove unnecessary inline modifier from test snippet

Ported from mozsearch/semanticdb-kotlinc@eb68377
…age collector

Previously handleException constructed a fresh CompilerConfiguration()
to retrieve the message collector key, which always fell back to
PrintingMessageCollector(System.err) — ignoring whatever collector the
actual compilation was configured with.

Pass the real CompilerConfiguration into PostAnalysisExtension so that
exception messages are routed through the same collector as all other
diagnostics. Also change the severity from EXCEPTION to WARNING, since
EXCEPTION is treated as isError=true by the Kotlin compiler and would
cause the build to fail — contrary to the plugin's intentional
"log-and-continue" behaviour.

The exception test now captures compiler output via result.messages and
asserts that the warning is actually emitted with the expected content,
rather than only checking the exit code.

Ported from mozsearch/semanticdb-kotlinc@e6b72f5
This is a test for 88f6272784c5e56eb135019a4b0dda5dd0808017.

Ported from mozsearch/semanticdb-kotlinc@2c1f170
…turn types

- local functions: verifies that named functions declared inside a
  function body receive local symbols (local0, local1), that explicit
  return type references are emitted (kotlin/Int#), and that call-site
  references resolve to the same local symbol. Also adds a
  SemanticdbSymbolsTest entry confirming the locals counter increments
  correctly.

- user-defined class as return type: verifies that SemanticSimple-
  FunctionChecker emits a REFERENCE occurrence for a user-defined class
  appearing in the return-type position (sample/MyClass#), exercising
  the returnTypeRef path that built-in types do not reach.

Ported from mozsearch/semanticdb-kotlinc@ff23a7e
displayName() in SemanticdbTextDocumentBuilder fell through to
`firBasedSymbol.toString()` for two symbol types, producing strings
like "FirTypeAliasSymbol sample/MyAlias" and "FirTypeParameterSymbol T"
instead of the short name.

- Broaden the FirClassSymbol branch to FirClassLikeSymbol so that
  FirTypeAliasSymbol (a subtype of FirClassLikeSymbol but not of
  FirClassSymbol) also uses classId.shortClassName.
- Add an explicit FirTypeParameterSymbol branch that returns
  symbol.name.asString().

Add tests that exercise the corrected paths:

- typealias: first test for SemanticTypeAliasChecker; verifies the
  DEFINITION occurrence and SymbolInformation (including the now-correct
  displayName "MyAlias"). Notes that type-alias references in value
  declarations are not currently tracked (the property checker resolves
  aliases to their expansion).

- type parameters: first test for SemanticTypeParameterChecker; verifies
  the DEFINITION occurrence and SymbolInformation (displayName "T").
  Notes that T in type-annotation positions does not produce REFERENCE
  occurrences because toClassLikeSymbol() returns null for type
  parameters.

Ported from mozsearch/semanticdb-kotlinc@20b1d20
…rrences

- Fix SemanticSimpleFunctionChecker and SemanticPropertyChecker to emit
  REFERENCE occurrences for extension receiver types
- Add SemanticEnumEntryChecker to emit DEFINITION occurrences for enum
  entries (previously missing from AnalyzerDeclarationCheckers)
- Fix semanticdbKind() to return Kind.ENUM_MEMBER for FirEnumEntry (FirEnumEntry
  extends FirVariable, which would otherwise map to Kind.LOCAL)
- Fix SemanticClassReferenceExpressionChecker (is/as operators) to use the
  already-extracted typeRef and source locals consistently rather than
  re-accessing expression.conversionTypeRef on each line
- Extract emitTypeRef() helper to reduce duplication across checkers; use it
  for supertype references in SemanticClassLikeChecker so they get the same
  fake-source guard as other type reference emissions
- Add tests for extension receivers, enum entries, named/unnamed companion
  objects, string template references, and is/as type references

Ported from mozsearch/semanticdb-kotlinc@d823d35
…uators

- multiple supertype references: verifies that SemanticClassLikeChecker
  emits REFERENCE occurrences for every entry in superTypeRefs, and that
  SymbolInformation.overriddenSymbols is populated for all supertypes
- three-way overload disambiguator: extends the existing two-overload
  coverage to three, verifying the (+1)/(+2) suffix counting logic in
  methodDisambiguator()

Ported from mozsearch/semanticdb-kotlinc@24b6433
The "non-0-based" phrasing predates this branch but is misleading: line
helpers return 1-based values (callers subtract 1 for protobuf), while
column helpers already return 0-based values. Make the docstrings say
what they actually return.

Ported from mozsearch/semanticdb-kotlinc@3059517
Add two test cases:

- enum entry with body (Op.PLUS { override ... }): the body is modeled
  as a synthetic anonymous subclass, so the entry gets a multi-line
  enclosing_range and the overridden member surfaces as a local symbol
  rather than a sample/Op#PLUS.apply() global. Asserts both.
- multi-line generic class declaration: general coverage we lacked for
  generic classes. Asserts enclosing_range for the class, its type
  parameter, and a member.

Ported from mozsearch/semanticdb-kotlinc@979f1f3
Changes in scip-kotlinc:
- Rename FirSimpleFunction -> FirNamedFunction in SemanticSimpleFunctionChecker
- Replace removed isLocalMember with isLocalDeclaredInBlock
  (moved within org.jetbrains.kotlin.fir.analysis.checkers.declaration)

Ported from mozsearch/semanticdb-kotlinc@832bf44

@samchon samchon left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit 3a1565d reserves stdout exclusively for resident NDJSON protocol frames, including the Gradle Tooling API cold distribution-download path, and strengthens the resident test to parse every stdout row as JSON. KotlinGraphGradleBuildToolTest and spotlessKotlinCheck passed locally. Downstream Ubuntu Koin acceptance at samchon/compiler-knowledge-graph@470e2d4 passed with the pinned producer: 3,613 nodes, 11,725 edges, no-op p95 3 ms, edit p95 1,907 ms, ordinary KGP daemon/incremental/classpath evidence, compiler-option universe invalidation, atomic failure/retry, and exact regeneration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants