Repository navigation
Semantic P4: compile type hints on SourceType; function-level @template + class-string<T> (#686) - #691
Closed
blacktrs wants to merge 140 commits into
Closed
Semantic P4: compile type hints on SourceType; function-level @template + class-string<T> (#686)#691blacktrs wants to merge 140 commits into
blacktrs wants to merge 140 commits into
Conversation
…user, last user file wins)
…iles that do not parse
…semantic tests and design doc
…onstants case-sensitively
…es, share constKey
…ed by the current compiler)
…do-types, class-constant refs, unsealed shapes, \Closure signatures); add typehint corpus tool
…HINT_CHECK shadow comparison
…tags (prose `@var T` typed Type::$interned as junk)
…ain reference, drop the legacy-interpolation site (cherry picked from commit 5052d09)
# Conflicts: # src/Semantic/NameIndex.php
…d delete the string ladder
lowerTypeHint parses each distinct hint string once into an immutable
Semantic\SourceType (class context applied at lowering) and lowers it with
lowerSource; an unparseable hint is unknown. Removes lowerTypeHintText,
lowerArrayShape, nullableUnionArm, isArrayUnion, isNumericUnion,
topLevelUnionArms, splitTopLevel, topLevelColon, lowerElemHint,
lowerCallableSignature and the MANTICORE_TYPEHINT_CHECK shadow mode.
Parser: accepts non-empty-array{...} / non-empty-list{...}; an unkeyed
shape entry after an int key takes key+1 (array{1: int, string} keys the
string 2); ?T|null parses as T|null. Behaviour changes on forms seen in no
corpus: null|callable(): T now lowers like callable(): T|null (closure,
was cell); Generator<array<int,string>> lowers its args
instead of splitting on the nested comma.
…rgs, key-of/value-of, class-string literal diagnostic
…ral as obj<T>, guarded by instanceof + TypeError (#686 step 4b)
…bstract/parent methods, inherited by undocumented overrides (#686)
Contributor
Author
|
Superseded by #691 (stacked PRs cannot be merged here). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
P4 of the semantic-core plan: the compiler reads docblocks and type hints through the shared semantic layer, and
@template T+class-string<T>bind at call sites in both the analyzer/LSP and the compiler.Stacked on #522 (
lsp-server).Changes
LowerTypesreads tags viaAnalyze\DocType;@param T &$xnow types the param. Tags inside backtick code spans / glued to words are prose, not tags.\Closure(...)signatures.tools/typehint_corpus.phpchecks coverage.lowerTypeHint= parse cache +lowerSource(SourceType)— string ladder deleted (−613 lines), IR byte-identical, front end −1.2% instructions. Shadow checkMANTICORE_TYPEHINT_CHECKfound 0 mismatches.Analyze\TemplateSig, binding fromFoo::class/class-string<Foo>/ T-typed args, substituted@return,key-of/value-of, phpstan > psalm > plain precedence, new ruletype.class-string.SourceType::CONDITIONAL($x is T ? A : B)(nested,is not), evaluated at the call in analyzer and compiler;string|class-string<T>params bind T.@template Treturnsobj<T>behindinstanceof+ TypeError guard (never a blind cast). Works for functions, methods, interface/abstract/parent declarations,{@inheritdoc}overrides; param/property/$thisreceivers.Not covered
Static calls on interfaces.
T|objectreturns (SymfonyContainerInterface::get) stayobject— faithful to the doc.Verification
bin/buildfixpoint each step (latestf89d50d1);analyze --json srcunchanged.class_string_arg, AOTtemplate_class_string_*(8, incl. lying-doc TypeError cases red on the previous compiler), filtered AOT runs green.