Commit Graph

2036 Commits

Author SHA1 Message Date
Suyash Srijan
3815eff366 Merge pull request #27641 from theblixguy/fix/mutating-fix-it
[AST] emitLetToVarNoteIfSimple should also check if the method/accessor is explicitly non-mutating
2019-10-14 20:09:41 +01: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
Suyash Srijan
3b5386e9a4 [AST] Removes the trailing space when replacing "nonmutating" with "mutating" via fix-it 2019-10-14 19:07:18 +01: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
Suyash Srijan
185d3bcec4 [AST] emitLetToVarNoteIfSimple should also check if the function or accessor is explicitly 'nonmutating'
Otherwise, we will simply insert the 'mutating' fix-it after 'nonmutating', leading to another error that says both cannot be used at the same time
2019-10-12 03:46:20 +01: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
Jordan Rose
171ff440fc Remove swift::reversed in favor of llvm::reverse (#27610)
The former predates the latter, but we don't need it anymore! The
latter has more features anyway.

No functionality change.
2019-10-10 17:16:09 -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
87cc09c02b AST: Remove some unnecessary calls to setGenericSignature() 2019-10-10 19:54:48 -04:00
Slava Pestov
3062b8c64a Sema: Move function result/subscript element type computation into a request
validateDecl() no longer explicitly validates the result TypeLoc.
Instead, the request is triggered via validateDecl() calling
computeType() on the FuncDecl or SubscriptDecl.
2019-10-10 19:54:48 -04:00
Slava Pestov
c20e5db802 AST: Re-implement getResultInterfaceType()/getElementInterfaceType()
In preparation for landing the ResultTypeRequest, let's compute
the result type directly from the declaration. For now, this still
forces getInterfaceType() to be computed, but that will go away
next.
2019-10-10 19:54:48 -04:00
Slava Pestov
12231d2df3 Merge pull request #27571 from slavapestov/circular-validation-cleanups-5
Circular validation cleanups, part 5
2019-10-10 19:52:56 -04:00
Jordan Rose
7725818275 Revert "Merge pull request #27057 from theblixguy/unrevert/SR-11298"
This reverts commit c99facb48b, reversing
changes made to 9a24013228.

rdar://problem/56165420
2019-10-10 14:29:52 -07: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
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
Varun Gandhi
04ce7bf779 Merge pull request #27557 from varungandhi-apple/vg-fix-selector-names
Use the accessor names as written in Objective-C.
2019-10-08 10:08:13 -07:00
Slava Pestov
64224cadcc Merge pull request #27553 from slavapestov/circular-validation-cleanups-4
Circular validation cleanups, part 4
2019-10-08 10:46:42 -04:00
Slava Pestov
fac36f95b0 Sema: Always use interface types in typeCheckParameterList() 2019-10-08 01:37:09 -04:00
Slava Pestov
a260d0a445 AST: getInterfaceType() returns ErrorType instead of Type() on circularity 2019-10-08 01:37:09 -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
Varun Gandhi
0d727d06a7 [NFC] Replace new getAccessor calls with getOpaqueAccessor calls.
It is fine if we synthesize the accessors a bit more than usual as
PrintAsObjC isn't performance-sensitive and IRGen needs the accessors
anyways.
2019-10-07 18:37:52 -07:00
Varun Gandhi
3b9dbd57c4 [AST] Get the ObjC accessor name, not the one parsed from Swift.
Fixes rdar://problem/55519276.
2019-10-06 06:57:50 -07: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
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
013c4f1540 Requestify whether a decl is an ABI compatible override (#27524)
Requestify whether a decl is an ABI compatible override
2019-10-03 19:09:11 -07:00
Slava Pestov
6702d38d87 Sema: Remove most calls to Decl::setValidationToChecked() 2019-10-03 17:11:45 -04: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
Brent Royal-Gordon
6456b39660 Fix StringInterpolationProtocol validation crasher
Some old circularity-breaking code caused an unexpected null type, which led to crashes in the decl checker when trying to check that an `appendInterpolation` method in a different file would satisfy the informal requirement for one in a StringInterpolationProtocol conformer. This code appears to now be unnecessary, so this commit removes it. Fixes rdar://problem/55864759.
2019-10-01 17:43:42 -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
adrian-prantl
00c64e7959 Merge pull request #27345 from adrian-prantl/16042546
Debug Info: Encode let-bindings using DW_TAG_const_type.
2019-09-27 14:39:56 -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