Commit Graph

1776 Commits

Author SHA1 Message Date
Robert Widmann
69bd40cafd Replace the cycle breaker for pattern bindings 2019-10-17 10:55:13 -07:00
Robert Widmann
198601dbd4 Bitpack the transitional API 2019-10-17 09:40:45 -07:00
Robert Widmann
8c73b7db58 Define NamingPatternRequest
Use it to provide an idealized API for the VarDecl case in validateDecl.

In reality, a lot of work is needed to rationalize the dependency
structure of this request.  To start, the callers of
typeCheckPatternBinding must be eliminated piecemeal.  Once that is
done, the AST should introduce pattern binding decls along all the
places where getParentStmt() used to apply.
2019-10-17 09:40:45 -07:00
Robert Widmann
71a525512d Define PatternBindingEntryRequest
Define a request that can be used to grab the fully validated and
type-checked form of a given pattern binding entry.  Using this,
validation of pattern bindings is fully disconnected from validation of
bound variables, and cycles are now picked up by the request evaluator.

Using this, we can go clean up all the callers that are checking a bit
and calling back into typeCheckPatternBinding.  It will also serve as
the basis for a request for the naming pattern for a VarDecl which will
clean that part of validateDecl.
2019-10-17 09:40:45 -07:00
Xi Ge
c8e18d4c19 AST: use a static allocated NullLocs to indicate no serialized source locations for a Decl, NFC 2019-10-15 16:48:20 -07:00
Xi Ge
c6035f68f0 AST: cache serialized source locations in Decl 2019-10-15 16:05:28 -07:00
Xi Ge
1e22e7c8aa AST: teach Decl::getLoc() to return serialized source loc.
When Decl::getLoc() is called upon a serialized AST and the
serialized source location is available, we lazily open the
external buffer and return a valid SourceLoc instance pointing
into the buffer.
2019-10-15 16:05:28 -07:00
Hamish Knight
899f145475 [AST] Add Unsafe[...]Buffer types as known decls 2019-10-15 10:12:47 -07:00
Robert Widmann
0082ba5abc Remove VarDecl::markInvalid
Inline the interface type reset into its callers and make sure they're
also setting the invalid bit - which this was not doing before.
Unfortunately, this is not enough to be able to simplify any part of var
decl validation.
2019-10-14 12:46:39 -07:00
Robert Widmann
742f6b2102 Drastically Simplify VarDecl Validation
This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl.  Instead, replace it with the
notion of a "naming pattern".  This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs.  This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl.  Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.
2019-10-14 12:06:50 -07:00
Robert Widmann
dd82b63f6c Push VarDecl's TypeRepr into ParamDecl
VarDecls inherit their TypeRepr from their enclosing pattern, if any.
To retrieve the TypeRepr attached to a VarDecl or a ParamDecl in
a uniform way, the getTypeReprOrParentPatternTypeRepr API has been
provided.
2019-10-14 12:06:16 -07:00
Hamish Knight
9061d3da71 CaptureInfo no longer needs to be passed by reference
Now that it's only a word in size, it can be passed
by value.
2019-10-13 12:10:26 -07:00
Slava Pestov
2e558f8c89 Merge pull request #27594 from slavapestov/circular-validation-cleanups-6
Circular validation cleanups, part 6
2019-10-12 00:59:21 -04:00
Robert Widmann
660f66d7c0 Delete the IsTypeLocImplicit Bit 2019-10-11 13:41:19 -07:00
Robert Widmann
2516089cb6 Clean up the pseudo-clone-constructor for ParamDecl 2019-10-11 11:51:50 -07:00
Robert Widmann
060cbb293f [NFC] Downgrade The TypeLoc in VarDecl to a TypeRepr
TypeCheckPattern used to splat the interface type into this, and
different parts of the compiler would check one or the other.   There is
now one source of truth: The interface type.  The type repr is now just
a signal that the user has written an explicit type annotation on
a parameter.  For variables, we will eventually be able to just grab
this information from the parent pattern.
2019-10-11 11:15:51 -07:00
Slava Pestov
90fa96d8fa Sema: Fold SubscriptDecl::computeType() into validateDecl() 2019-10-10 19:55:02 -04:00
Slava Pestov
09034fdf66 Sema: Fold EnumElementDecl::computeType() into validateDecl() 2019-10-10 19:55:02 -04:00
Slava Pestov
6974448b1e Sema: Fold TypeAliasDecl::computeType() into validateDecl() 2019-10-10 19:55:02 -04:00
Slava Pestov
797a7974bc Sema: Fold NominalTypeDecl::computeType() into validateDecl() 2019-10-10 19:55:01 -04:00
Slava Pestov
87dd47aeaa Sema: Fold AssociatedTypeDecl::computeType() into validateDecl() 2019-10-10 19:54:48 -04:00
Slava Pestov
6701a7efcf AST: Remove unused method declaration 2019-10-10 15:28:35 -04:00
Slava Pestov
3dbdc09a4e Sema: Move ParamDecl interface type computation to validateDecl()
This eliminates typeCheckParameterList() altogether.
2019-10-10 15:28:14 -04:00
Slava Pestov
d8b61ff24b Sema: Peel off typeCheckParameterList()'s specifier computation into a request
Since getSpecifier() now kicks off a request instead of always
returning what was previously set, we can't pass a ParamSpecifier
to the ParamDecl constructor anymore. Instead, callers either
call setSpecifier() if the ParamDecl is synthesized, or they
rely on the request, which can compute the specifier in three
specific cases:

- Ordinary parsed parameters get their specifier from the TypeRepr.

- The 'self' parameter's specifier is based on the self access kind.

- Accessor parameters are either the 'newValue' parameter of a
  setter, or a cloned subscript parameter.

For closure parameters with inferred types, we still end up
calling setSpecifier() twice, once to set the initial defalut
value and a second time when applying the solution in the
case that we inferred an 'inout' specifier. In practice this
should not be a big problem because expression type checking
walks the AST in a pre-determined order anyway.
2019-10-10 15:00:07 -04:00
Slava Pestov
df62f3629b AST: Rename ParamDecl::Specifier to ParamSpecifier
Nested types cannot be forward declared which poses difficulties
for the request evaluator.
2019-10-10 14:34:26 -04:00
Slava Pestov
03ae7a206f AST: Remove unused EnumDecl::getElement() method 2019-10-08 18:39:00 -04:00
Slava Pestov
a6b5824dac AST: Correctly set parent DeclContext of ParamDecls in EnumElementDecls
When an EnumElementDecl is parsed, we create the parameter list before
creating the EnumElementDecl itself, so we have to re-parent those
ParamDecls just like we do for functions and subscripts.
2019-10-08 18:39:00 -04:00
Hamish Knight
91a792b393 Merge branch 'master' into id-like-to-request-a-table 2019-10-07 22:05:30 -07:00
Slava Pestov
52cf3659b5 Sema: Simplify validateDecl()
Remove the early return in the case where one of our parent contexts was
being validated, and replace it with a simpler check that is only
performed in some callers related to associated type inference; we want
to bail out in one specific case only, which is that the declaration
is inside an extension whose generic signature is in the process of
being computed.
2019-10-07 22:20:18 -04:00
Slava Pestov
1d809801e1 AST: Add ValueDecl::isRecursiveValidation()
This will be used as a transitional aid in refactoring getInterfaceType()
to always return a valid type, instead of silently returning Type() when
there is circularity.
2019-10-07 22:20:18 -04:00
Slava Pestov
6bfe518344 AST: Compute FuncDecl::isStatic() using a request 2019-10-07 22:20:18 -04:00
Slava Pestov
e334e5d66f AST: Convert ValueDecl::getOpaqueResultTypeDecl() into a request
Instead of depending on a prior call to setOpaqueResultTypeDecl(),
we can instead just build the decl if we need one.
2019-10-04 22:11:07 -04:00
Hamish Knight
3f66608cb5 Check for stubs in NeedsNewVTableEntryRequest
This lets us remove `setNeedsNewVTableEntry`.
2019-10-03 19:13:39 -07:00
Hamish Knight
c1a1ddd458 Requestify needsNewVTableEntry
This commit introduces `NeedsNewVTableEntryRequest`,
which checks whether a class method needs a new
vtable entry.
2019-10-03 19:13:39 -07:00
Hamish Knight
934d4d1d87 Requestify whether a decl is an ABI compatible override
This commit adds `IsABICompatibleOverrideRequest`,
which checks if the decl is an override, and if
so whether it's ABI compatible with the base
This is then usedto replace the logic for
computing  `isValidKeyPathComponent` in addition
to being used in `requiresNewVTableEntry`.
2019-10-02 21:06:22 -07:00
Robert Widmann
2fe3ce8af8 Requestify the Raw Value Accessor
Make getRawValueExpr() return a checked value.

This entails a strange kind of request that effectively acts like
a cache warmer.  In order to properly check the raw value expression for
a single case, we actually need all the other cases for the
autoincrementing synthesis logic.  The strategy is therefore to have the
request act at the level of the parent EnumDecl and check all the values
at once.  We also cache at the level of the EnumDecl so the cache
"warms" for all enum elements simultaneously.

The request also abuses TypeResolutionStage to act as an indicator for
how much information to compute.  In the minimal case, we will return
a complete accounting of (auto-incremented) raw values.  In the maximal
case we will also check and record types and emit diagnostics.  The
minimal case is uncached to support repeated evaluation.

Note that computing the interface type of an @objc enum decl *must*
force this request.  The enum's raw values are part of the ABI, and we
should not get all the way to IRGen before discovering that we cannot
possibly lay out the enum.  In the future, we might want to consider
moving this check earlier or have IRGen tolerate broken cases but for
now we will maintain the status quo and not have IRGen emit
diagnostics.
2019-10-02 16:09:25 -07:00
Mishal Shah
2f86d67500 Merge pull request #27396 from shahmishal/master-rebranch
Update master to support apple/stable/20190619 branch for LLVM projects
2019-10-01 10:50:49 -07:00
Robert Widmann
75670c1727 Merge pull request #27436 from CodaFi/signed-sealed-delivered
[NFC] Adopt TypeBase-isms for GenericSignature
2019-09-30 15:50:42 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
swift-ci
26a8bf8e75 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-30 08:43:50 -07:00
David Ungar
ea81fdc7d8 Merge pull request #27313 from davidungar/generic-request-or-extended-nominal-assertion
Fail early if getExtendedNominal is called before extension has been bound.
2019-09-30 08:37:33 -07:00
David Ungar
4bc4030338 Catch failures earlier caused by premature requests for extended nominal 2019-09-28 15:19:32 -07:00
swift-ci
67e0f740c1 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-27 11:23:52 -07:00
Xi Ge
4069172a40 AST: refactor getLoc() of decls to have a single entry point for all decl kinds, NFC
After we start to serialize the result of getLoc() in the
.swiftsourceinfo file, getLoc() needs a single entry point to look up via
USRs in the serialized format.
2019-09-26 17:47:44 -07:00
swift-ci
349d6b073e Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-26 12:44:18 -07:00
Harlan Haskins
b904133c42 [Modules] Add flag to skip non-inlinable function bodies
This flag, currently staged in as `-experimental-skip-non-inlinable-function-bodies`, will cause the typechecker to skip typechecking bodies of functions that will not be serialized in the resulting `.swiftmodule`. This patch also includes a SIL verifier that ensures that we don’t accidentally include a body that we should have skipped.

There is still some work left to make sure the emitted .swiftmodule is exactly the same as what’s emitted without the flag, which is what’s causing the benchmark noise above. I’ll be committing follow-up patches to address those, but for now I’m going to land the implementation behind a flag.
2019-09-26 10:40:11 -07:00
swift-ci
170a84c5bd Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-25 18:44:16 -07:00
Robert Widmann
dd7d925610 Merge pull request #27364 from CodaFi/raw-smackdown
Clean up enum raw expression validation a bit
2019-09-25 18:43:20 -07:00
swift-ci
cb97094e71 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-25 13:44:21 -07:00
Robert Widmann
0df6b40710 Clean up enum raw expression validation a bit
The distinction between the type checked raw value expression and the regular raw value expression was never important.  Downstream clients were ignoring the type checked form and pulling the text out of the supposed "plain" form.  Drop the distinction and simply don't set back into the raw value expr if we don't have to.

Pushing this through naturally enables some cleanup in checkEnumRawValues.  Factor out type checking the literal value into an helper on the typechecker and pull a common diagnostic into the decl checker.
2019-09-25 11:14:47 -07:00