Commit Graph

1923 Commits

Author SHA1 Message Date
Mark Lacey
defc293e1b [SIL] Replace a use of getInput() in classifyDynamicCast.
Use getParams() instead.
2018-07-28 23:34:25 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Slava Pestov
585b06e647 AST: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 12:28:26 -07:00
Doug Gregor
1b63b688bf [AST] Use TinyPtrVector for the list of overridden declarations.
TinyPtrVector is a more-space-efficient SmallVector<_, 1>. Use it.
2018-07-18 16:56:43 -07:00
Doug Gregor
b70466dc63 [Type Checker] Add a request kind for computing 'ValueDecl::isObjC()'.
Still a WIP
2018-07-18 14:50:39 -07:00
Doug Gregor
8f23915334 [Type Checker] Introduce a request for “overridden declarations”.
Introduce a new request kind to capture the computation of the set of
overridden declarations of a given declaration, eliminating the
stateful “setOverriddenDecls()” calls from the type checker.
2018-07-18 14:50:38 -07:00
Slava Pestov
42a3ad3bf0 AST: Fix over-eager collapseSpecializedConformance()
It's possible that the conforming type is equal to the generic
conformance type, but some of the substitutions replace an
abstract conformance with a concrete one.

In this case we cannot collapse away the specialized conformance,
because we lose information that way.

Fixes <rdar://problem/40164371>.
2018-07-17 14:41:49 -07:00
David Zarzycki
bae6cc6017 Merge pull request #17767 from davezarzycki/enable_opt_unowned_unmanaged
Enable optional unowned/unowned(unsafe) references
2018-07-17 14:13:44 -04:00
Arnold Schwaighofer
c820a1426f Silence unused variable warning 2018-07-12 10:33:25 -07:00
Arnold Schwaighofer
ba1facf12e ASTContext: Recompute the insert position in getSpecializedConformance after the SpecializedProtocolConformance constructor
The constructor can modify the SpecializedConformances FoldingSet so that the
insertPos is no longer valid. It calls computeConditionalRequirements which
calls Type::subst which recursively can call getSpecializedConformance again.

This bug manifest itself either as memory error with libgmalloc or as
spurious errors later on.

rdar://42082352
2018-07-12 10:29:07 -07:00
David Zarzycki
71472cfa96 Enable optional unowned/unowned(unsafe) references
John okayed this change in a comment on GitHub pull request: #16237
2018-07-11 14:33:23 -04:00
Joe Groff
9833fb4dee SIL: Assert that SILFunctionTypes are only @pseudogeneric when they have generic arguments.
And fix up the places where we would set or propagate the 'pseudogeneric' bit even for nongeneric types.
2018-07-06 15:36:57 -07:00
Graydon Hoare
9b87c7be4e Merge pull request #17734 from graydon/access-level-request
Access level request
2018-07-05 16:30:04 -07:00
Graydon Hoare
205347321f [AST] Auto-register AST-level requests on ASTContext construction. 2018-07-05 13:00:28 -07:00
John McCall
34b0cbc11d Merge pull request #16237 from davezarzycki/metaprogram_ref_storage_types
[AST] NFC: Enable reference storage type meta-programming
2018-07-05 14:45:38 -04:00
Slava Pestov
45fb11ce3c AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass
More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
2018-07-02 22:06:33 -07:00
Doug Gregor
764f14807f [AST] Centralize the storage of the overridden declarations of a declaration.
Several kinds of declarations can override other declarations, but the
computation and storage for these “overridden” declarations was scattered in
at least 3 different places, with different resolution paths. Pull them
all together into two bits of LazySemanticInfo in ValueDecl (“have we computed
overrides?” and “are there any overrides?”), with a side table for the
actual list of overrides.

One side effect here is that the AST can now represent multiple overridden
declarations, although only associated type declarations track this
information.

Start using LazyResolver::resolveOverriddenDecl() more consistently, unifying
it with the separate path we had for associated type overrides. All of this
is staging for a move to the request-evaluator for overridden declaration
computation.
2018-07-02 14:51:28 -07:00
David Zarzycki
5b9f5062f9 [AST] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
Doug Gregor
197642d37b [Request-evaluator] Track # of evaluations for each request kind.
Using the unified stats reporter, track the # of evaluations for each
type checking request kind.
2018-06-22 00:01:55 -07:00
Doug Gregor
b1b3c43c59 [Request-evaluator] Add -debug-cycles flag to print cycles.
As a debugging aid, introduce a new frontend flag `-debug-cycles` that
will emit a debug dump whenever the request-evaluator encounters a cyclic
dependency, while otherwise allowing compilation to continue.
2018-06-16 10:29:52 -07:00
Doug Gregor
9843190300 [Request-evaluator] Disable cycle diagnostics when used in the type checker.
The type checker has *lots* cycles, and producing diagnostics for them
at this point in the development of the request-evaluator is not
productive because it breaks currently-working code. Disable cycle
diagnostics for now when using the request-evaluator in the type
checker. We'll enable it later as things improve, or as a separate
logging mode in the interim.
2018-06-14 15:29:57 -07:00
Doug Gregor
b7fbe57bf9 [AST] Remove “validated” bit from TypeLoc.
TypeLocs have been “validated” when they have a non-null Type, so eliminate
the separate “validated” bit that was out-of-sync with the Type field.
2018-06-14 15:29:57 -07:00
Doug Gregor
ef337bb8ba [Evaluator] Use the request-evaluator for the superclass of a class.
Wire up the request-evaluator with an instance in ASTContext, and
introduce two request kinds: one to retrieve the superclass of a class
declaration, and one to compute the type of an entry in the
inheritance clause.

Teach ClassDecl::getSuperclass() to go through the request-evaluator,
centralizing the logic to compute and extract the superclass
type.

Fixes the crasher from rdar://problem/26498438.
2018-06-14 15:28:36 -07:00
John McCall
e97fde0a32 Merge pull request #17212 from rjmccall/generalize-accessor-kinds
Rename accessor kinds from IsGetter -> IsGet, etc.
2018-06-14 18:06:39 -04:00
John McCall
9022b5152f Rename accessor kinds from IsGetter -> IsGet, etc.
Introduce some metaprogramming of accessors and generally prepare
for storing less-structured accessor lists.

NFC except for a change to the serialization format.
2018-06-14 17:08:55 -04:00
Jordan Rose
85275d278e Add some more PrettyStackTrace entries to AST (#17208)
No functionality change.
2018-06-14 13:55:52 -07:00
Robert Widmann
bdebb774bb [NFC] Refactor intrinsic candidate search code
- De-templatize the intrinsic candidate search functions.
- Allow callback predicates access to the candidate's function type so they can evalute its parameters/return value themselves.
2018-06-12 10:03:19 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Slava Pestov
b3bc06e75e Merge pull request #16766 from AnthonyLatsis/generalize_declared_here
[Sema] Generalize the 'declared here' diagnostic
2018-05-22 19:47:53 -07:00
fischertony
7313a90eb1 [Sema] Generalize the 'declared here' diagnostic 2018-05-22 18:17:15 +03:00
Slava Pestov
ebb1198d57 AST: There's no longer any reason to pass SubstitutionMap by const reference
SubstitutionMaps are now just a trivial pointer-sized value, so
pass them by value instead.

I did have to move a couple of functors from Type.h to SubstitutionMap.h
to resolve some issues with forward declarations.
2018-05-19 00:45:36 -07:00
David Zarzycki
8404cd73f2 [AST] NFC: Pair AlignedFree with AlignedAlloc (found via ASAN) 2018-05-11 06:08:44 -04:00
Rintaro Ishizaki
9fc09858ae [AST] Stop using side-table for local discriminators 2018-05-11 15:37:01 +09:00
Jordan Rose
88169d6898 Merge pull request #16489 from jrose-apple/to-put-it-in-context
Make sure protocol witness errors don't leave the conformance context
2018-05-10 21:44:33 -07:00
Jordan Rose
6bd7e5e5b4 Make sure protocol witness errors don't leave the conformance context
That is, if there's a problem with a witness, and the witness comes
from a different extension from the conformance (or the original type,
when the conformance is on an extension), put the main diagnostic on
the conformance, with a note on the witness. This involves some
shuffling and rephrasing of existing diagnostics too.

There's a few reasons for this change:

- More context. It may not be obvious why a declaration in file
  A.swift needs to be marked 'public' if you can't see the conformance
  in B.swift.

- Better locations for imported declarations. If you're checking a
  conformance in a source file but the witness came from an imported
  module, it's better to put the diagnostic on the part you have
  control over. (This is especially true in Xcode, which can't display
  diagnostics on imported declarations in the source editor.)

- Plays better with batch mode. Without this change, you can have
  diagnostics being reported in file A.swift that are tied to a
  conformance declared in file B.swift. Of course the contents of
  A.swift also affect the diagnostic, but compiling A.swift on its
  own wouldn't produce the diagnostic, and so putting it there is
  problematic.

The change does in some cases make for a worse user experience,
though; if you just want to apply the changes and move on, the main
diagnostic isn't in the "right place". It's the note that has the info
and possible fix-it. It's also a slightly more complicated
implementation.
2018-05-10 19:31:12 -07:00
David Zarzycki
09d71117b5 [ASTContext] NFC: Align Impl offset before pointer arithmetic, not after
This generates better code and is a follow up to #16469.
2018-05-10 17:20:02 -04:00
David Zarzycki
f0c106c0e3 [AST] NFC: Avoid pointer indirection with ASTContext Impl storage
Most of this change is mechanical: `Impl` -> `getImpl()`.
2018-05-10 05:50:56 -04:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Jordan Rose
18162a3ed0 Revert "AST: Simplify ModuleDecl::forAllVisibleModules()"
This reverts commit 0c32c54e36.
2018-05-03 22:40:37 -06:00
Doug Gregor
2feb830b58 [SubstitutionMap] Only profile the replacement types for canonical parameters.
When building a substitution map, the client is only responsible for filling
in the replacement types for canonical generic parameters; the others
(e.g., those for generic parameters for which there is a same-type
constraint) can be filled in lazily. Profiling them leads to incorrect
uniquing of SubstitutionMap.

Fixes the rest of rdar://problem/39949332.
2018-05-03 15:16:02 -07:00
Doug Gregor
4136a1897a [AST] Split SubstitutionMap::Storage into its own header.
Now that SubstitutionMap is used in so many places, reduce it's header
dependencies by moving SubstitutionMap::Storage into its own separate
implementation header. Use forward declarations of other entities
(GenericSignature, Substitution) instead.

Good for build times and general sanity.
2018-05-03 09:49:09 -07:00
Doug Gregor
9c5a222b95 Merge pull request #16291 from DougGregor/ast-use-substitution-map
[AST] Store SubstitutionMaps in the AST rather than Substitution lists.
2018-05-02 23:52:18 -07:00
Jordan Rose
df2e63d07d Diagnose modules with circular dependencies (#16075)
This can't arise from a clean build, but it can happen if you have
products lingering in a search path and then either rebuild one of
the modules in the cycle, or change the search paths.

The way this is implemented is for each module to track whether its
imports have all been resolved. If, when loading a module, one of its
dependencies hasn't resolved all of its imports yet, then we know
there's a cycle.

This doesn't produce the best diagnostics, but it's hard to get into
this state in the first place, so that's probably okay.

https://bugs.swift.org/browse/SR-7483
2018-05-02 15:01:09 -07:00
Doug Gregor
bc5bbe8b64 [AST] Use SubstitutionMap, not SubstitutionList, in SILBoxType.
Eliminate the last place in the AST proper that stores
SubstitutionLists rather than SubstitutionMaps. Randomly fixes a
crasher, too.
2018-05-02 13:39:21 -07:00
Doug Gregor
3e2bed119b [AST] Switch SpecializedProtocolConformance over to SubstitutionMap.
Eliminate another common use of SubstitutionList from the AST.
2018-05-02 13:38:15 -07:00
Doug Gregor
6bdd24d1ac Merge pull request #16268 from DougGregor/substitution-map-ast-adoption
[AST] Adopt SubstitutionMap as the storage mechanism for substitutions
2018-04-30 20:36:02 -07:00
Doug Gregor
df97e44eb9 [AST] Replace SubstitutionList in NameAliasType with a SubstitutionMap.
Convert NameAliasType’s internal representation from tail-allocating an
array of Substitutions (to be treated as a SubstitutionList) to store a
single SubstitutionMap. Serialize using that SubstitutionMap.
2018-04-30 16:23:14 -07:00
swift-ci
39612dc2a5 Merge pull request #16249 from DougGregor/flatten-substitution-map 2018-04-30 14:07:01 -07:00
Doug Gregor
cdff7427f8 [AST] Unique and ASTContext-allocate SubstitutionMaps.
Prepare for SubstitutionMaps to be stored in other AST nodes by making
them ASTContext-allocated and uniqued (via a FoldingSet). They are now
cheap to copy and have trivial destructors.
2018-04-30 10:42:03 -07:00
Slava Pestov
af875829a7 Merge pull request #16206 from slavapestov/serialization-cleanup
Serialization cleanup
2018-04-27 05:22:40 -07:00