Commit Graph

409 Commits

Author SHA1 Message Date
Slava Pestov
544e0a02d5 AST: Don't link together GenericParamLists of nested generic types
GenericParamList::OuterParameters would mirror the nesting structure
of generic DeclContexts. This resulted in redundant code and caused
unnecessary complications for extensions and protocols, whose
GenericParamLists are constructed after parse time.

Instead, lets only use OuterParameters to link together the multiple
parameter lists of a single extension, or parameter lists in SIL
functions.
2018-12-11 23:55:41 -05:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Mark Lacey
018498fb2f Merge pull request #16942 from bjhomer/bjhomer/optional-try-flattening
Flatten nested optionals resulting from try? and optional sub-expressions
2018-11-16 11:14:05 -08:00
Arnold Schwaighofer
40f0c43e31 Add isNativeDynamic() and use it 2018-11-14 12:04:41 -08:00
Slava Pestov
c7338d06ca AST: Remove owning addressors 2018-11-09 20:49:44 -05:00
Jordan Rose
4270bddaeb Verify that a GenericTypeParamDecl's depth and index are correct (#20445)
Re-applied after fixing a bug in Serialization where the DeclContext
wasn't being set correctly for extensions with nested parameters. I
was unable to come up with a reduced test case, but the CoreStore
project in the source compatibility suite was failing without the
Serialization change, and now it isn't.
2018-11-09 08:58:55 -08:00
Jordan Rose
6a15b26d0e Revert "Verify that a GenericTypeParamDecl's depth and index are correct" (#20432)
This reverts #20100 / commit 0bf65f102d.
It's causing problems on the Source Compatibility bot.
2018-11-08 12:28:04 -08:00
John McCall
4758b2f58e Fix a bug with class vs. protocol @_borrowed mismatches. 2018-11-08 02:16:47 -05:00
Arnold Schwaighofer
44b3a47e56 Merge pull request #20333 from aschwaighofer/dynamic_function_replacement
Dynamic function replacement
2018-11-07 13:08:46 -08:00
Jordan Rose
0bf65f102d Verify that a GenericTypeParamDecl's depth and index are correct (#20100)
(with respect to the containing GenericParamList)
2018-11-07 11:22:29 -08:00
BJ Homer
df6be36457 Add backwards-compatible behavior for swift-version < 5 2018-11-06 23:31:02 -07:00
BJ Homer
3ae807d4bf Make 'try?' flatten optional chaining like optional-chaining does.
If the sub-expression of the 'try?' is optional, the result will be the same level of optional-ness.
If the sub-expression is non-optional, the result is optional.

Thus, the following lines all end up with the same type of 'Int?'
 - let x = try? 3 as Int
 - let x = try? 3 as? Int
 - let x = try? 3 as Int?
2018-11-06 23:31:02 -07:00
Arnold Schwaighofer
c158106329 Allow dynamic without @objc in -swift-version 5
Dynamic functions will allow replacement of their implementation at
runtime.
2018-11-06 09:53:21 -08:00
Pavel Yaskevich
17b04ba800 [ASTVerifier] Fix pre-check to look at subscript arguments
`array-to-pointer` and other conversions are not restricted to apply
expressions, (dynamic) subscript arguments have them too, which
verifier has to support.

Resolves: rdar://problem/45825806
2018-11-06 00:28:44 -08:00
John McCall
cf511445e2 Basic support for Builtin.IntegerLiteral. 2018-10-31 18:42:34 -04:00
Vinicius Vendramini
b61df445ae Cleans up calls to print/dump for the AST Dumper
The `Stmt` and `Expr` classes had both `dump` and `print` methods that behaved similarly, making it unclear what each method was for. Following a conversation in https://forums.swift.org/t/unifying-printing-logic-in-astdumper/15995/6 the `dump` methods will be used to print the S-Expression-like ASTs, and the `print` methods will be used to print the more textual ASTPrinter-based representations. The `Stmt` and `Expr` classes seem to be where this distinction was more ambiguous. These changes should fix that ambiguity.

A few other classes also have `print` methods used to print straightforward representations that are neither the S-Expressions nor ASTPrinters. These were left as they are, as they don't cause the same ambiguity.

It should be noted that the ASTPrinter implementations themselves haven't yet been finished and aren't a part of these changes.
2018-10-22 16:04:02 -03:00
Slava Pestov
c2d96a7a6f AST Verifier: Don't canonicalize types unless they contain archetypes
Canonicalizing GenericFunctionTypes is a very expensive operation, and
we assert elsewhere that they do not contain archetypes.
2018-09-26 23:24:14 -07:00
Michael Gottesman
c62f31f5dc Inject llvm::SmallBitVector into namespace swift;
I also eliminated all llvm:: before SmallBitVector in the code base.
2018-09-21 09:49:25 -07:00
Harlan
665db876ea [InterfaceGen] Print bodies of inlinable functions in textual interfaces (#19224)
* Introduce stored inlinable function bodies

* Remove serialization changes

* [InterfaceGen] Print inlinable function bodies

* Clean up a little bit and add test

* Undo changes to InlinableText

* Add serialization and deserialization for inlinable body text

* Allow parser to parse accessor bodies in interfaces

* Fix some tests

* Fix remaining tests

* Add tests for usableFromInline decls

* Add comments

* Clean up function body printing throughout

* Add tests for subscripts

* Remove comment about subscript inlinable text

* Address some comments

* Handle lack of @objc on Linux
2018-09-14 10:23:15 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Xi Ge
033732b1e5 ASTVerifier: avoid verifying IterableDeclContext if it has unparsed members. 2018-09-12 14:11:41 -07:00
Slava Pestov
3dfd8e3993 Sema: Set the type of ParenExpr to ParenType
This eliminates a hack I just added in coerceCallArguments().
2018-09-11 12:43:03 -07:00
Slava Pestov
ea6b397b51 AST: Refactor AST verifier checks for TupleShuffleExpr
Change a couple of getAs() to castTo(), so that we assert instead of
crashing with a null pointer dereference if a TupleShuffleExpr has
the wrong type.
2018-09-10 17:22:31 -07:00
Slava Pestov
351490c098 AST: Add verifier checks for FuncDecl::hasForcedStaticDispatch() 2018-09-06 16:59:01 -07:00
Slava Pestov
8801aa67d3 Merge pull request #19133 from slavapestov/access-level-cleanup
Access level cleanup
2018-09-06 16:46:40 -07:00
Slava Pestov
a5281df841 Sema: Move getFormalAccess() from validateDecl() to finalizeDecl()
Note that the verifier can no longer assert that validated
declarations have access, because... they don't! And there's
no separate verification level for finalized declarations,
so I'm just going to remove that check.
2018-09-05 16:57:40 -07:00
Doug Gregor
0972111c60 [Type checker] Start tracking overrides of protocol requirements.
When a protocol that inherits another protocol restates a requirement
from its inherited protocol, track that as an override in the AST.
2018-09-04 16:42:06 -07:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04:00
Slava Pestov
95c035fe3f Merge pull request #18985 from slavapestov/lazy-self-param
Consolidate code for creating 'self' parameter and only create it when needed
2018-08-25 12:23:32 -07:00
Slava Pestov
c360c82850 AST: Automatically create the 'self' parameter when needed
Parsed declarations would create an untyped 'self' parameter;
synthesized, imported and deserialized declarations would get a
typed one.

In reality the type, if any, depends completely on the properties
of the function in question, so we can just lazily create the
'self' parameter when needed.

If the function already has a type, we give it a type right there;
otherwise, we check if a 'self' was already created when we
compute a function's type and set the type of 'self' then.
2018-08-25 10:44:55 -07:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Doug Gregor
0e81b40ae0 [AST Verifier] Remove verifyProtocolList().
The property that we are checking for here isn’t really local to the
nominal type or extension declaration, and triggers semantic queries
that aren’t needed elsewhere. Remove it, because it’s not adding value.
2018-08-13 22:31:09 -07:00
Slava Pestov
f11b6200b1 AST: Set invalid bit in ValueDecl::setInterfaceType()
The verifier asserts that declarations whose interface type contains an error
are invalid, so let's just mark them invalid when we set the interface type,
instead of needlessly duplicating this logic all over the declaration checker.
2018-08-10 13:33:12 -07:00
Joe Groff
bfb1a072ac AST verifier: Verify invariants of ErasureExprs. 2018-08-07 14:50:20 -07:00
Doug Gregor
3018becde7 [Type checker] Eliminate type checking from early extension binding.
Use ExtensionDecl::getExtendedNominal() to wire up extensions to their
nominal types early in type checking (the bindExtensions()) operation,
rather than going through type validation to do so.
2018-08-03 11:26:49 -07:00
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -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
90cd772228 AST: Remove getParameterLists() and friends from AbstractFunctionDecl subclasses
Now, an AbstractFunctionDecl always stores a single parameter list.

Furthermore, ConstructorDecl and DestructorDecl always store a
ParamDecl for 'self'.

FuncDecl only has a 'self' if it is a member of a nominal type or
extension, so we tail-allocate the storage for it.
2018-07-22 20:56:56 -07:00
Slava Pestov
ac6e970477 AST: Add a new verifier check for methods 2018-07-21 01:25:06 -07:00
Slava Pestov
585b06e647 AST: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 12:28:26 -07:00
Doug Gregor
8514225c58 [AST Verifier] Drop checks that don’t work with lazily-computed overrides. 2018-07-18 14:50:38 -07:00
Doug Gregor
5815a81922 [AST Verifier] Don’t ask to compute overridden declarations.
Don’t ask to compute overridden declarations that haven’t already been
computed.
2018-07-18 14:50:38 -07:00
Mark Lacey
7798b9f877 Partial fix for verification of where pointer conversions can appear.
The existing verification seems unnecessarily brittle, but this isn't
a general fix for that problem. This fixes one instance of where we
are generating perfectly valid pointer conversions that the verifier
is currently blowing up on.

I've opened https://bugs.swift.org/browse/SR-8264 to track reworking
this verification to not be quite so brittle.
2018-07-15 23:10:38 -07:00
Pavel Yaskevich
871a436d35 [ASTVerifier] Make sure that immediate paren/force-value is outside of load 2018-07-07 11:50:42 -07:00
Slava Pestov
381483bd74 AST: Remove Expr's LValueAccessKind 2018-07-05 23:54:13 -07:00
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07: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
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Robert Widmann
a7c9bd09db Merge pull request #17181 from CodaFi/in-put-up-and-in-shut-up
[IDE] Scrub SwiftIDE of References to getInput()
2018-06-16 11:14:49 -07:00