Commit Graph

141 Commits

Author SHA1 Message Date
Slava Pestov
0b320a6d5b Sema: Implement DefaultWitnessChecker
Now that WitnessChecker is separate from ConformanceChecker, implement
a DefaultWitnessChecker subclass which performs default witness
resolution.

This populates the recently-added ProtocolDecl::DefaultWitnesses map.

Unlike ConformanceChecker, the DefaultWitnessChecker looks up the witness
in any protocol extensions of the protocol, matching the context archetypes
of the requirement against the witness.

For now, we infer default witnesses for all protocols, but don't do
anything with that information. An upcoming SILGen patch will start to
emit thunks and add tests.
2016-03-03 06:59:55 -08:00
Slava Pestov
5b89f7fd6a SIL: Use interface types in the SIL parser
The SIL parser used PolymorphicFunctionType in two places:

- Internals of SILFunctionType parsing

- Overload selection for class_method / super_method / dynamic_method
  instructions

It is better to have Sema construct GenericFunctionType directly
in SIL mode. In particular, the overload selection logic is simpler
now, since it does not have to deal with the fact that
PolymorphicFunctionTypes do not canonicalize.

Mostly NFC, except the SIL printer output is a bit different; for a
generic method on a generic type, the type parameters all come first,
like ``<T><U> G<T> -> (U) -> ()'' -vs- ``<T> G<T> -> <U> (U) -> ()''.

Also, generic constraints look different, instead of ``<`Self` : P>``
we now have ``<Self where Self : P>''.

This patch has two consequences that will become important later:

- While code that constructs PolymorphicFunctionType still exists in
  Sema, the SIL parser was the last major component that *consumed*
  PolymorphicFunctionType.

- Everywhere we set SILFunction::ContextGenericParams, we now have
  a well-formed context GenericSignature available, allowing
  ContextGenericParams to be replaced by a GenericSignature
  eventually.
2016-02-01 20:49:14 -08:00
Denis Vnukov
42cba88f2c Properly handle tokens split in parser inside swift::tokenize(...)
Swift parser splits tokens in few cases, but it swift::tokenize(...) does not know
about that. In order to reconstruct token stream as it was seen by the parser,
we need to collect the tokens it decided to split and use this information
in swift::tokenize(...).
2016-01-27 13:43:39 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Michael Gottesman
4fae42e7bf [irgen] Refactor out the pass pipeline build code in IRGen so that llvm-swift-opt can use it.
llvm-swift-opt is a swift only version of opt that will be used to remove
swift's dependency on dynamically injecting passes into opt and to allow for
IRGen's LLVM pipeline to be simulated exactly by reusing the IRGen pass pipeline
building code.

The reason to remove the dynamic code is that it seems that this is code that
will be in flux vis-a-vis the transition to the new pass manager in LLVM, so it
makes sense to make this change now due to the benefit provided by exactly
simulating IRGen.

Swift SVN r32804
2015-10-21 21:45:18 +00:00
Adrian Prantl
0de0d43773 Introduce a -modulewrap driver action that wraps a (merged) .swiftmodule
inside a swift ast section in an object file so it can be passed to the
linker. The driver automatically wraps merged swiftmodules iff the target
is ELF.

rdar://problem/22407666

Swift SVN r31641
2015-09-02 21:56:25 +00:00
Devin Coughlin
3e96e1f06b [Sema] Suppress warning about useless availability checks in playgrounds and immediate mode.
We normally report a warning when a #available() check will always be true
because of the minimum deployment target. These warnings are potentially
annoying when the developer either cannot change the minimum deployment target
from the default (as in playgrounds) or when doing so is burdensome (as for
interpreted command-line scripts, which would require passing a target triple)
-- so suppress them.

The is a updated version of the reverted r29582, which didn't check for
immediate mode properly.

rdar://problem/21324005

Swift SVN r29646
2015-06-24 23:09:22 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Chris Willmore
d3a977d824 <rdar://problem/20402026> Remove scope entry/exit log entries
Don't emit scope entry/exit logging code in instrumentation for
playgrounds if -playground-high-performance option is passed.

Swift SVN r27046
2015-04-06 22:09:20 +00:00
Luqman Aden
3f83973928 Handle multiple sib inputs.
Swift SVN r26572
2015-03-26 01:21:21 +00:00
Manman Ren
d39f8e49a8 [Driver] make Swift accept bitcode input.
Thanks Jordan for reviewing the patches.
rdar://19048891


Swift SVN r25558
2015-02-26 19:31:09 +00:00
Manman Ren
26431e0eac Update interface of getIRTargetOptions. Review feedback from Jordan.
Swift SVN r25441
2015-02-20 23:33:05 +00:00
Dmitri Hrybenko
f6faf8ad81 sil-opt: implement partial AST verification
... and use it to parallelize the parse_stdlib.sil test, which was
taking too long.

Swift SVN r25295
2015-02-14 11:48:11 +00:00
Jordan Rose
8612e24e0f -debug-time-function-bodies: dump time spent type-checking each function.
This is a hidden frontend-only option intended for debugging purposes,
mainly for identifying where in a file the type checker is spending most
of its time. Use with "sort -g" to get the top problem functions.

Swift SVN r23789
2014-12-08 23:07:07 +00:00
John McCall
2e60c2947d Revert "Summon the eldritch horror "EagerDeserializationDecls" from the bowels of history."
This reverts commit dc98e17d84b991b6be8b8feb5e0d05aad24f52a4.

I believe this commit was causing test failures on:
  IRGen/c_layout.sil
  IRGen/existentials.sil
It also recreates the file lib/Serialization/ModuleFormat.h,
which really can't have been intended.

Swift SVN r23732
2014-12-05 06:53:27 +00:00
Joe Groff
df53d4bd80 Summon the eldritch horror "EagerDeserializationDecls" from the bowels of history.
Adding explicit constructors to Clang-imported structs in the previous commits exposes a latent phase ordering issue between the Clang importer and SIL deserialization. Deserializing the standard library SIL ends up pulling in additional Clang decls which never get type-checked before we attempt to emit their code. Work around this by bringing back the "EagerDeserializedDecls" block in the serialization format, and adding any cross-referenced decls that get referenced in SILSerializeAll mode to it, so that we ensure they're available before SILGen. We also have to type-check external decls after doing so, since when only importing a module, we wouldn't do any type-checking at all otherwise.

Swift SVN r23728
2014-12-05 05:31:25 +00:00
Michael Gottesman
85e2502f96 Pass in SILOptions to SILModule.
This should have been done a long time ago since SILOptions are options that
should be able to effect everything SIL related. In this case I just want to
pass in a flag on the SILModule to enable +0 self. By putting it on the
SILModule I can conveniently check it in SILFunctionType without exposing any
internal state from SILFunctionType.cpp.

Swift SVN r23647
2014-12-03 07:43:52 +00:00
Joe Groff
17e85e60e4 Consistently set target, CPU, and subtarget options in AOT and JIT mode.
Factor out the code that sets up llvm::TargetOptions and SubtargetFeatures via Clang, and reuse it in immediate mode to properly set up the ExecutionEngine to be consistent with the environment we emitted code for. This makes it so that we can use code that lowers to, for instance, SSE3 intrinsics, in particular stuff like GLKit code imported from Clang.

Swift SVN r23646
2014-12-03 06:40:18 +00:00
Denis Vnukov
ca208dfc8c Extending ParserUnit to optionally accept LangOptions and module name.
Needed by fix in SourceKit which will be submitted later (rdar://problem/18945845, 
SourceKit crashed in SourceKit::SwiftEditorDocument::replaceText()).



Swift SVN r23511
2014-11-21 16:38:18 +00:00
Doug Gregor
b3badc601a Handle consistency checking that requires the entire module.
Objective-C method unintended override checking is one such case where
properly checking unintended overrides requires us to essentially look
at the whole module, because one translation unit may declare
something that produces an Objective-C method "setFoo:" in a
superclass while another translation unit declares something with a
distinct name that produces an Objective-C method "setFoo:". So, when
we don't have a primary file (e.g., when we're doing the merge-module
step), delay such checks until after all the source files for the
module have been type-checked. When there is a primary file, we
perform the checking that we can based on type checking that primary
file (and whatever got touched along the way), so we get a subset of
the proper diagnostics.

Swift SVN r23179
2014-11-08 06:20:57 +00:00
Erik Eckstein
43f68b6974 Enable dead function removal for internal function in whole-module compilation.
This is controlled by a new isWholeModule() attribute in SILModule.

It gives about 9% code size reduction on the benchmark executables.
For test-suite reasons it is currently not done for the stdlib.



Swift SVN r22491
2014-10-03 14:14:23 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Jordan Rose
90c76906bd [Serialization] Wrap up serialization options into a class.
No functionality change.

Swift SVN r21542
2014-08-28 21:35:57 +00:00
Manman Ren
0b19aaf716 [SILParser] handle generic signature with depth.
Here is how we parse SILFunctionType:
1> Printer will print the generic signature of SILFunctionType by splitting the
   requirement lists by depth.
2> Parser will parse the printed generic signature as nested generic parameter
   lists, and will construct generic signature from the generic parameter lists
   by calling getAsCanonicalGenericSignature.
3> When parsing the substitution list of an ApplyInst, we assume the order of
   the substitutions match the order of AllNestedArchetypes.

Parsing of back-to-back generic parameter lists is only enabled in SIL mode.

Another option is to parse generic signatures directly, but at SIL level, we
need to access Archetypes and they are currently built from generic parameter
lists. That means we have to reconstruct both generic signatures and generic
parameter lists.

rdar://17963350


Swift SVN r21421
2014-08-22 21:26:36 +00:00
Nadav Rotem
54458fb892 Enable access control based devirtualization.
Patch (mostly) by Jordan Rose.

rdar://17890078. 



Swift SVN r21139
2014-08-12 00:43:18 +00:00
Nadav Rotem
f9d4a84e18 Remove the rest of the tryFinal logic. rdar://17890078.
Swift SVN r21138
2014-08-12 00:06:35 +00:00
Michael Ilseman
1df56990bd Also try to add final to non-public members of public classes.
Teaches TryAddFinal to descend into public and objc classes. Only
tries to add final if we're either whole compilation mode, or we're
processing the primary source buffer.

Updates test cases. Includes workarounds for <rdar://problem/17860781>
and <rdar://problem/17862348>.

Swift SVN r20790
2014-07-31 00:32:50 +00:00
Michael Ilseman
41dec5b58c Invoke TryAddFinal after type checking.
Run whole-module checks at the end of perform Sema, specifically
TryAddFinal. After everything has been type checked, accessibility has
been provided, and we have had a chance to see any potential
overrides, we try to add the final attribute to class members.

This ends up de-virtualizing many functions, or rather they avoid the
vtable altogether. Thus, there are many test file changes. New test
file add_final.swift. Other tests updated to either reflect the
non-virtual call, or to have public added to them.

Swift SVN r20338
2014-07-22 21:31:58 +00:00
Argyrios Kyrtzidis
8eb7d43d32 [Parser] Introduce a convenience wrapper for Parser functionality.
This is useful when wanting to just do some syntactic parsing for a snippet of code.

Swift SVN r20174
2014-07-18 19:57:32 +00:00
Manman Ren
866f306e62 [SILParser] refactor handleSILGenericParams to prepare patches for parsing.
No functionality change.
Change signature of handleSILGenericParams to get ready for patches on parsing
specialized protocol conformance in sil_witness_table.

rdar://15722175


Swift SVN r18117
2014-05-15 18:27:50 +00:00
Sean Callanan
6f473fe048 Added a new entry point to the type checker to
allow it to type-check any new external methods
that appeared since type-checking last occurred.
This allows the playground transform to add new
dependencies on external functions.

Thanks to Jordan Rose for the suggestion and
review.

<rdar://problem/16835585>


Swift SVN r17830
2014-05-10 19:14:23 +00:00
Jordan Rose
dde2a8b06b Serialize and honor whether a particular library should be force-loaded.
When a module built with -autolink-force-load is imported, add a reference
to a special symbol in the corresponding library so that ld is forced to
link it.

This means the library will be linked into the final binary even if no other
symbols are used (which happens for some of our overlays that just add
category methods to Objective-C classes).

Second part of <rdar://problem/16829587>

Swift SVN r17751
2014-05-09 01:20:32 +00:00
Jordan Rose
465b083ba9 [serialization] Serialize the header path used by -import-objc-header.
This doesn't handle cross-references to decls /loaded/ from the header
just yet, so all that's testable right now is whether the header's imports
are visible from the secondary target (after being imported in response
to loading the serialized module).

More of <rdar://problem/16702101>

Swift SVN r17638
2014-05-07 19:03:21 +00:00
Jordan Rose
a0de0e411d [serialization] Drop swift::serializeToStream and swift::serializeModuleDoc.
All serialization should go through serialize(). We don't currently support
serializing docs without serializing a module.

Also, tidy up how Serializer is used within Serialization.cpp.

Swift SVN r17637
2014-05-07 19:03:19 +00:00
Manman Ren
b96ddf48d6 SILParser: parsing GenericParamList.
To parse GenericParamList in SILParser, we try to share code with TypeChecker.
We add handleSILGenericParams in Subsystems.h in order for SILParser to call
TypeChecker's handling of GenericParamList (this is motivated by the example of
SILParser calling performTypeLocChecking). handleSILGenericParams calls
checkGenericParamList and finalizeGenericParamList.

A Builder field (ArchetypeBuilder*) is added to GenericParamList so we can add
the same-type requirements to GenericSignature in getAsCanonicalGenericSignature
by checking SameTypeRequirements of the builder.

resolvePotentialArchetypeToType is moved from a static helper function in
TypeCheckGeneric.cpp to a public helper function in ArchetypeBuilder.cpp.
When constructing the same-type requirements in getAsCanonicalGenericSignature,
we will call it to convert from PotentialArchetype to a dependent type.

rdar://16238241


Swift SVN r14922
2014-03-11 18:01:01 +00:00
Dmitri Hrybenko
e50b52fa02 Serializer/Driver: serialize comments to separate .swiftdoc files
The driver infers the filename from the module file by replacing the extension,
and passes the explicit path to the swiftdoc file to the frontend.  But there
is no option in the driver to control emission of swiftdoc (it is always
emitted, and name is always inferred from the swiftmodule name).

The swiftdoc file consists of a single table that maps USRs to {brief comment,
raw comment}.  In order to look up a comment for decl we generate the USR
first.  We hope that the performance hit will not be that bad, because most
declarations come from Clang.  The advantage of this design is that the
swiftdoc file is not locked to the swiftmodule file, and can be updated,
replaced, and even localized.


Swift SVN r14914
2014-03-11 10:42:26 +00:00
Sean Callanan
3b95376949 Added a new AST transformation pass called the
"Playground Transform."  This is an
instrumentation pass that adds calls to a
function called playground_log at locations of
interest.  Roughly speaking, these locations are

- Initialization of variables
- Modification of variables
- Expressions returning values
- Application of mutating methods on objects

The playground transform currently only finds
modifications of variables, but the intent is to
make all of these cases work.

It is enabled by a frontend option, and can
also be invoked by calling

swift::performPlaygroundTransform(SF)

which is the way LLDB, its main client, will
use it.

The frontend option is intended for testing,
and indeed I will add tests for this
transformation in the coming week as I bring
more functionality online.


Swift SVN r14801
2014-03-07 22:59:19 +00:00
John McCall
10ac15ed0d Lex $notAllDigits as an identifier and diagnose it in the lexer
outside of debugger-support mode.  Rip out the existing special-case
code when parsing expr-identifier.

This means that the Lexer needs a LangOptions.  Doug and I
talked about just adding that as a field of SourceMgr, but
decided that it was worth it to preserve the possibility of
parsing different dialects in different source files.

By design, the lexer doesn't tokenize fundamentally differently
in different language modes; it might decide something is invalid,
or it might (eventually) use a different token kind for the
same consumed text, but we don't want it deciding to consume more or
less of the stream per token.

Note that SIL mode does make that kind of difference, and that
arguably means that various APIs for tokenizing need to take a
"is SIL mode" flag, but we're getting away with it because we
just don't really care about fidelity of SIL source files.

rdar://14899000

Swift SVN r13896
2014-02-14 01:54:17 +00:00
Jordan Rose
0de8d19514 Define globals for the names of the stdlib, ObjectiveC, and Foundation modules.
This is mostly useful for the standard library, whose name is going to
change to "Swift" soon. (See <rdar://problem/15972383>.) But it's good DRY.

Swift SVN r13758
2014-02-10 22:40:42 +00:00
Mark Lacey
5c696fda8b Make IR generation take an explicit LLVMContext.
Prior to r13134, the modules being constructed for IRGen always used the
LLVM global context due to <rdar://problem/15283227>, but the interface
should really take this as a parameter rather than baking the behavior
into IRGen.

Swift SVN r13260
2014-02-01 01:07:14 +00:00
Jordan Rose
bac31d985a Add '-sil-serialize-all' testing option to the new frontend.
Swift SVN r13190
2014-01-31 01:02:06 +00:00
Jordan Rose
101fd40076 Rip out -emit-module-for-lldb option.
We ended up not using the wrapper around the module data in the Mach-O.

Swift SVN r13185
2014-01-31 00:02:47 +00:00
Jordan Rose
fb21a2da84 Move LLVM passes into a library, and use opt to test them instead of swift.
These don't really have anything to do with Swift, and there's no reason to
include this capability in the new driver.

Swift SVN r13181
2014-01-30 23:42:38 +00:00
Mark Lacey
d69b305200 Generate IR for inline functions from Clang modules.
Currently only inline functions referenced from Swift source files, or
from the REPL, will get IR generated for them. Inline functions
referenced by other inline functions will require additional effort to
generate properly.

With this change we use the clang::CodeGenerator-created llvm::Module
for all IR generation in Swift. This is perhaps undesirable, but
unavoidable given the interface the public Clang APIs expose, which do
not allow for building a ModuleBuilder that borrows an existing
llvm::Module.

Also unfortunate is the hack to generate a UsedAttr for each imported
inline function, but the public Clang APIs do not provide a way to only
emit deferred decls without emitting other things (e.g. module flags
that conflict with what the Swift IRGen emits). Note that we do not do
IRGen for every inline function in the module - only the ones that the
importer pulls in, which appears to be only those transitively
referenced from Swift code.

Swift SVN r13134
2014-01-30 02:33:37 +00:00
Jordan Rose
c312e51962 Add the ability to serialize modules with LLDB's wrapper info around them.
Currently when compiling with debug info, the AST gets serialized into the
.o file for use by the debugger. However, when we switch to one .o file
per .swift file, this won't really make sense any more. Instead, we should
collect all the ASTs at the end of the build and merge them together, then
write /that/ into the final binary.

This commit handles writing a serialized AST with an LLDB wrapper around it,
so that we can take a merged AST, write it out in the wrapper, and splice it
into the final binary using ld's -sectcreate option.

In the long run, we probably won't need the LLDB wrapper, but for now I'm
trying to disturb as little as possible. (It looks like the layout is
broken on 32-bit platforms, though...there was a problem with 64-bit
relocations in the existing SwiftASTStreamerPass, but nothing ever tried to
/read/ the new layout in 32 bits. I'm holding off on dealing with this
right now.)

Part of <rdar://problem/15786017>

Swift SVN r12667
2014-01-21 23:13:26 +00:00
Argyrios Kyrtzidis
e244f51229 [Lexer] Add some const goodness to the SourceManager that the Lexer uses.
No functionality change.

Swift SVN r12182
2014-01-11 01:09:30 +00:00
Connor Wakamo
59f18f9fc0 Renamed irgen::Options and irgen::OutputKind to IRGenOptions and IRGenOutputKind, and move both out of the irgen namespace now that they're in swiftAST.
Swift SVN r11405
2013-12-18 01:17:09 +00:00
John McCall
7173cec9db Thread contextual information about parsing the top-level
through various bits and use that to globally discriminate.

Swift SVN r11379
2013-12-17 04:31:40 +00:00