Commit Graph

399 Commits

Author SHA1 Message Date
Robert Widmann
74765a8ba8 Remove Type Body Fingerprints Flags
This infrastructure has more than proven itself. Drop the code paths and tests supporting the status quo.
2020-10-01 13:09:00 -07:00
Slava Pestov
f718a4cdd2 AST: Remove IterableDeclContext::getMemberCount() 2020-09-23 01:26:06 -04:00
Robert Widmann
934f994b46 Remove DeclContext::isCascadingContextForLookup 2020-09-21 10:37:41 -06:00
Doug Gregor
ccca4fd25d [AST] Add IterableDeclContext::getParsedMembers().
Provide an accessor for retrieving the parsed members, generalizing
`ParseMembersRequest` so it can provide the parsed members for
deserialized/synthesized declarations as well. This is the counterpart
to the recently-generalized `getSemanticMembers()`; together, these
should suffice for most (all?) clients of `getMembers()`.
2020-09-01 13:58:30 -07:00
Doug Gregor
650a8b25da [AST] Rename EmittedMembersRequest -> SemanticMembersRequest. 2020-09-01 13:21:59 -07:00
Doug Gregor
ae4fbb6716 [AST] Generalize and rename ClassDecl::getEmittedMembers()
Generalize `ClassDecl::getEmittedMembers()` to operate on an
`IterableDeclContext`, so that it can be for other nominal types,
extensions, etc. Rename to `getSemanticMembers()` to indicate that
these are all of the members that are semantically part of that
context.

Clean up the implementation slightly so it only forces type checking
for the conformances within that particular context (using
`getLocalConformances()`) and doesn't need to list out each of the
protocols it cares about.
2020-09-01 13:01:10 -07:00
Slava Pestov
769c4c1911 Sema: Fix some crashes with invalid nesting of extensions and protocols
Make sure we consistently use getParentForLookup() and not getParent()
when looking at generic DeclContexts. This is because an extension or
protocol that is nested inside of another generic context must never
inherit generic parameters from the parent context.

We already had this invariant enforced in some places, but now that we
do it more consistently we can fix more crashes of this kind.

Fixes <rdar://problem/58813746>, <https://bugs.swift.org/browse/SR-13004>.
2020-07-28 02:07:16 -04:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Anthony Latsis
c337757964 [NFC] Sema: get rid of redundant DeclContext parameter to checkConformancesInContext 2020-05-20 02:38:24 +03:00
Anthony Latsis
55447e66aa Merge pull request #31645 from AnthonyLatsis/relocate-to-iterabledc
[NFC] AST: Relocate some conformance lookup client methods from DeclContext to IterableDeclContext
2020-05-18 22:25:08 +03:00
Anthony Latsis
edcf7640c0 [NFC] AST: Define and use IterableDeclContext::getAsGenericContext() 2020-05-08 03:15:07 +03:00
Slava Pestov
edb71db1c6 AST: Diagnose references to non-public declarations from default arguments of inlinable local functions
Part of <https://bugs.swift.org/browse/SR-12404>.
2020-05-04 15:38:46 -04:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Slava Pestov
e2349bdf67 AST: Move TypeChecker::getFragileFunctionKind() to a method on DeclContext
We had some duplicated logic between getResilienceExpansion() and
getFragileFunctionKind(). Clean this up by moving the latter into
AST, and re-implementing the former in terms of the latter.

This also fixes a crash in at least one case where these two
implementations had previously diverged.

Fixes <rdar://problem/60605117>.
2020-04-16 14:09:04 -04:00
Dan Zheng
c834696bfa Add SynthesizedFileUnit.
`SynthesizedFileUnit` is a container for synthesized declarations. Currently, it
only supports module-level declarations.

It is used by the SIL differentiation transform, which generates implicit struct
and enum declarations.
2020-04-07 18:29:26 -07:00
Robert Widmann
f13c76cf51 Add ModuleDecl Base Case To extractNearestSourceLoc
ModuleDecl is its own declaration context.
2020-04-03 14:52:21 -07:00
Robert Widmann
27b211c1f9 Lazy-load the eraser of @_typeEraser where possible
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
2020-04-03 14:52:21 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Alexis Laferrière
c61cc6fe4e [AST] Add SPI information to public access scopes 2020-03-04 16:42:18 -08:00
David Ungar
72032493f9 Fix and test for extension body 2020-02-29 23:19:09 -08:00
Brent Royal-Gordon
f8df2f66fd Add mechanism for per-SourceFile overlays
When a “separately imported overlay” is added to a SourceFile, two things happen:

1. The direct import of the underlying module is removed from getImports*() by default. It is only visible if the caller passes ImportFilterKind:: ShadowedBySeparateOverlay. This means that non-module-scoped lookups will search _OverlayModule before searching its re-export UnderlyingModule, allowing it to shadow underlying declarations.

2. When you ask for lookupInModule() to look in the underlying module in that source file, it looks in the overlays instead. This means that UnderlyingModule.foo() can find declarations in _OverlayModule.
2020-02-18 11:07:12 -08:00
David Ungar
8f4fd061f9 Use Optional for fingerprint 2020-01-27 15:14:46 -08:00
David Ungar
d61f6f2f66 Changes to support per-type-body fingerprints. 2020-01-27 15:14:46 -08:00
Robert Widmann
e626cfb378 Remove lazy member loading re-entrancy guards
Effectively revert #28907. The request evaluator will also catch re-entrancy here, and those cycles can be broken with NameLookupFlags::IgnoreNewExtensions.
2020-01-25 11:04:53 -08:00
Suyash Srijan
37b40203a7 [AST] Remove redundant 'return false' from 'hasValueSemantics()' 2019-10-15 01:35:46 +01:00
Suyash Srijan
6665e716c5 [AST] Use getExtendedProtocolDecl() to check for protocol extension and use getDeclaredInterfaceType() instead of getSelfTypeInContext() - both are cheaper 2019-10-15 01:35:46 +01:00
Suyash Srijan
6ca121dd2a [Typechecker] Do not incorrectly mark explicitly mutating methods as non-mutatingif we're in a class-constrained protocol extension 2019-10-15 01:35:46 +01:00
Suyash Srijan
70d77e9fe2 Revert "Revert "Merge pull request #27057 from theblixguy/unrevert/SR-11298""
This reverts commit 7725818275.
2019-10-15 01:35:46 +01: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
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
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
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
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Suyash Srijan
c99facb48b Merge pull request #27057 from theblixguy/unrevert/SR-11298
Unrevert "[Sema] Setter has incorrect mutating-ness inside class-constrained protocol extension"
2019-09-18 01:15:07 +01:00
Suyash Srijan
d9c8ae4ce8 [AST] Remove isTypeContext() check from hasValueSemantics() and move the responsibility to the caller 2019-09-17 18:38:01 +01:00
Suyash Srijan
0d66b0c5df [AST] Fix indenation in hasValueSemantics() 2019-09-17 01:24:02 +01:00
David Ungar
5ee5dee2f3 Merge pull request #27171 from davidungar/memberCount-fix
[NameLookup ASTScope] Ensure memberCount includes unparsed members
2019-09-13 16:28:24 -07:00
Sasha Krassovsky
1e414f7fb6 Fix warnings in AST 2019-09-13 09:57:48 -07:00
David Ungar
f184f75bf0 Ensure memberCount includes unparsed members 2019-09-12 14:08:24 -07:00
Suyash Srijan
e8fe05d9bb [AST] hasValueSemantics() should check whether the current context is a type context before proceeding 2019-09-11 01:03:22 +01:00
Suyash Srijan
29ca8b0b38 [AST] Adds 'hasValueSemantics()' to DeclContext and uses 'getSelfTypeInContext()' instead 2019-09-09 21:17:27 +01:00
Robert Widmann
d4bb9a5cfe Define GenericParamListRequest
GenericParamListRequest formalizes the lazy generic parameter list construction pattern we were performing before.
2019-09-06 17:22:30 -07:00
Slava Pestov
0405ab5ffc AST: GenericContexts store a GenericSignature instead of a GenericEnvironment
This eliminates the entire 'lazy generic environment' concept;
essentially, all generic environments are now lazy, and since
each signature has exactly one environment, their construction
no longer needs to be co-ordinated with deserialization.
2019-09-06 17:16:04 -04:00
Doug Gregor
d8f7c9e72c [Parser] Introduce a request for parsing type and extension members.
Ensure that lazy parsing of the members of nominal type definitions
and extensions is handled through a request. Most of the effort here
is in establishing a new request zone for parser requests.
2019-08-28 21:39:56 -07:00
Slava Pestov
b92918889f AST: Don't cache NominalTypeDecl::getDeclaredTypeInContext() 2019-08-22 01:46:50 -04:00
Slava Pestov
2d475a9ee9 AST: Simplify DeclContext::mayContainMembersAccessedByDynamicLookup() 2019-08-19 23:00:57 -04:00