Commit Graph

753 Commits

Author SHA1 Message Date
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
swift-ci
2689ff9343 Merge remote-tracking branch 'origin/master' into master-next 2019-10-30 07:49:45 -07:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Xi Ge
64c0680686 Merge remote-tracking branch 'apple/master' into master-next 2019-10-28 10:19:36 -07:00
Robert Widmann
86e5ed18a0 Add a bailout path to protocol requirement source formation
The GSB will try to form and note invalid constraints, but there are
a few paths that aren't prepared for error types to pop up.  Add
a defensive check to formProtocolRelativeType to make sure we don't wind
up force-casting an error type.

Fixes rdar://56116278
2019-10-25 13:08:41 -07:00
swift-ci
e4cbf824ae Merge remote-tracking branch 'origin/master' into master-next 2019-10-11 15:10:04 -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
swift-ci
d499a49526 Merge remote-tracking branch 'origin/master' into master-next 2019-10-08 06:29:18 -07:00
David Zarzycki
df078830e4 NFC: silence a few warnings 2019-10-04 10:48:04 +03:00
swift-ci
b30a6ae2ee Merge remote-tracking branch 'origin/master' into master-next 2019-10-03 08:29:37 -07:00
Saleem Abdulrasool
85b6a0542c AST: remove dump for GSB
This relied on UB as per [meta.rqmts]p4
(http://eel.is/c++draft/meta#rqmts-4) and has been UB since C++11
20.9.2p1 has the same restriction.

MSVC 19.24 became more stringent and silently ignores this now,
preventing the Swift build.  Require the user to explicitly pass in
`-DSWIFT_PERMIT_UNDEFINED_BEHAVIOR` to get the dump functionality.
2019-10-02 11:20:43 -07:00
swift-ci
5e50242b5e Merge remote-tracking branch 'origin/master' into master-next 2019-09-30 16:09:53 -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
2891ea3897 Merge remote-tracking branch 'origin/master' into master-next 2019-09-25 06:50:22 -07:00
Slava Pestov
040be292e5 AST: TypeDecl::getDeclaredInterfaceType() always returns a non-empty Type
In the case of circular type aliases, this now returns ErrorType
instead of Type().
2019-09-24 22:38:59 -04:00
Slava Pestov
edd5105452 AST: Clean up usages of TypeAliasDecl::getStructuralType()
This also gets rid of a usage of TypeAliasType::get().
2019-09-24 22:38:59 -04:00
swift-ci
e0a9ae468a Merge remote-tracking branch 'origin/master' into master-next 2019-09-24 15:29:49 -07:00
Robert Widmann
574a450537 Extensions Do Not Have Parent Signatures
Remove the parent signature from consideration when computing the
generic signature for an extension.  This cuts off a series of crashers
that involved nested extensions with trailing where clauses a la

extension Foo {
  extension Foo where Self.Undefined == Bar {
  }
}

The inner (invalid) extension technically has a parent signature from
Foo itself.  Adding that signature to the GSB means when we go to
register the inner extension's generic parameters we crash.

Since extensions have to occur at the top level, just remove the parent
signature from consideration.

Fixes rdar://55502661
2019-09-24 13:13:51 -07:00
swift-ci
714ed6f1d6 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 17:50:04 -07:00
Robert Widmann
bddb2c72df [NFC] Address review feedback from #27172
- Clean up some errant formatting mistakes.
- Collapse some code that was duplicating computing the interface type.
2019-09-18 16:21:23 -07:00
swift-ci
8ce5b01307 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 15:09:47 -07:00
Robert Widmann
38bde33067 Merge pull request #27172 from CodaFi/aliasing-artifacts-and-noise-reduction-techniques
Kill validateDeclForNameLookup Harder
2019-09-18 15:00:51 -07:00
swift-ci
a453eda2dc Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 10:09:53 -07:00
Robert Widmann
6b7fbc9a2b Break some cycles
Use the interface type of the underlying type in the GSB in as many
cases as possible except for one important one: requirement signature
computation.  There, use the structural type so we don't wind up
recursively validating the requirements of an incomplete protocol.
2019-09-17 18:29:40 -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
Robert Widmann
c254f4d2f8 Setting the underlying type should set the structural type too
This avoids making the structural type dependent on whether the interface type has been computed and neatly avoids special-casing non-parsed declarations which set their underlying type up front.
2019-09-17 08:49:03 -07:00
Robert Widmann
5e34169aca Separate computing interface types and underlying types
Computing the interface type of a typealias used to push validation forward and recompute the interface type on the fly.  This was fragile and inconsistent with the way interface types are computed in the rest of the decls.  Separate these two notions, and plumb through explicit interface type computations with the same "computeType" idiom.  This will better allow us to identify the places where we have to force an interface type computation.

Also remove access to the underlying type loc.  It's now just a cache location the underlying type request will use.  Push a type repr accessor to the places that need it, and push the underlying type accessor for everywhere else.  Getting the structural type is still preferred for pre-validated computations.

This required the resetting of a number of places where we were - in many cases tacitly - asking the question "does the interface type exist".  This enables the removal of validateDeclForNameLookup
2019-09-17 08:20:55 -07:00
swift-ci
edbbed5c18 Merge remote-tracking branch 'origin/master' into master-next 2019-09-16 17:49:20 -07:00
Robert Widmann
e0a41b19cb Break some cycles
Computing the generic signature changes the way that cycles appear in the compiler.  For now, break these cycles.  We should investigate each place where hasComputedGenericSignature() is used in service of breaking cycles.  See rdar://55263708
2019-09-16 12:50:24 -07:00
Mike Ash
f5e7ab866c Merge branch 'master' into master-next 2019-09-09 12:11:25 -04:00
Robert Widmann
eb79f3e528 Move helpers on RequirementRequest to WhereClauseOwner 2019-09-06 11:49:37 -07:00
swift-ci
c8948180f8 Merge remote-tracking branch 'origin/master' into master-next 2019-09-04 17:29:49 -07:00
Robert Widmann
87047d067e Requestify Inferring Generic Requirements
Unify a bunch of quasi-independent callsites into a single request that
builds up a generic signature from a variety of inference sources.  This
draws the extension typealias workaround for SE-0229 into TypeCheckDecl
where we can better work on refactoring it.  The goal is to use this as
a springboard to requests that compute generic environments for various
and sundry decls.
2019-09-03 09:56:21 -07:00
Arnold Schwaighofer
20efacf2d6 Merge remote-tracking branch 'upstream/master' into master-next 2019-08-26 13:30:41 -07:00
Doug Gregor
8ad76a1707 Canonicalize requests for the abstract generic signature.
When a request for an abstract generic signature contains noncanonical
types, first compute the abstract generic signature for the
canonicalized types, then map back to the provided generic
parameters. Clients of this request generally work in canonical types
already, but it's a small win.
2019-08-26 09:54:20 -07:00
Doug Gregor
70c73ec175 Don't create a generic signature builder when only adding parameters.
If we are creating a generic signature without any requirements, we
can form the signature directly; it's well-formed by definition.
2019-08-26 09:54:20 -07:00
Doug Gregor
a23a4353cb [Type checker] Requestify the formation of an abstract generic signature
Introduce a request to form an abstract generic signature given a
base signature, additional generic parameters, and additional
requirements. It is meant to provide a caching layer in front of the
generic signature builder.

Switch one direct client of the generic signature builder over to this
mechanism, the formation of a generic signature for an existential
type.
2019-08-26 09:54:19 -07:00
swift-ci
b503ced230 Merge remote-tracking branch 'origin/master' into master-next 2019-08-22 16:29:14 -07:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Slava Pestov
24da27b179 AST: Verify that all generic signatures can be re-built from their requirements
-verify-generic-signatures didn't catch the bad case from
<https://bugs.swift.org/browse/SR-10752>. Add a new check and
make sure it now catches this kind of failure.
2019-06-14 16:00:37 -07:00
Harlan Haskins
5a3761df1b [Sema] Stop filtering nested protocol types from lookup
This check wasn't ever correct, because the fact that the the protocol comes
from another module doesn't change the fact that the type is valid for lookup
within this module. It incorrectly rejects the following, valid code:

```swift
// In A.swift
public protocol A {}
```

```
// In B.swift
import A

extension A {
  typealias B = Int
  func b(_ b: Self.B) {}
}
```
2019-06-13 17:54:35 -07:00
Slava Pestov
c947eda18f AST: Use ProtocolDecl::getAssociatedTypeMembers() where possible 2019-05-28 22:08:31 -04:00
Slava Pestov
ecf45db7bb GSB: Remove call to markConformanceUsed() 2019-05-28 22:08:31 -04:00
Slava Pestov
4643cbd8e9 GSB: Remove another call to resolveDeclSignature()
The GSB should avoid triggering declaration validation where
possible, to avoid problems resulting from circularity and as
a general performance rule-of-thumb.

This last call was there to catch self-recursive protocol
typealiases. However, we can diagnose this problem elsewhere,
which allows us to emit a more accurate diagnostic as well.
2019-05-10 15:00:48 -04:00
Alexis Laferrière
cfae7bba3d Avoid cycles when computing a requirement signature
Replace most remaining uses of isRequirementSignatureComputed by
isRequirementSignatureComputing which uses Evaluator::hasActiveRequest
to detect if the requirements are currently being computed.
2019-05-09 10:50:45 -07:00
Alexis Laferrière
6c929273db Intro a request to compute the requirement signature of a ProtocolDecl
Replaces the explicit call to computeRequirementSignature from
validateDecl with a lazy getRequirementSignature. A side effect is that
the generic params of a ProtocolDecl are no longer computed from
validateDecl and must be computed lazily too.
2019-05-08 14:28:35 -07:00