Commit Graph

6754 Commits

Author SHA1 Message Date
Chris Lattner
e07994c9c8 Two changes:
- Fix a misunderstanding I had about ownership requirements in my previous patch:
   now any references to value-promoted self do a retain and use a ManagedValue,
   just like the semantic load path used to.  This is the change to visitLoadExpr
 - Second, change argument lowering to drop the "self" argument of normal class
   methods into a constant reference, instead of making a box for it.  This 
   greatly reduces the amount of SIL generated for class methods.

The argument lowering piece is somewhat hacky because initializations really want
to be dealing with memory, but it seemed like the best approach given the current
design.  Review appreciated.



Swift SVN r10984
2013-12-07 21:30:38 +00:00
Chris Lattner
73ea257446 remove an old and apparently unnecessary hack in pattern lowering for arguments.
Disable the copyaddr peepholes when the loadexpr is from a constant VarDecl.


Swift SVN r10982
2013-12-07 08:19:38 +00:00
Chris Lattner
8c7ff5bcef inline a lambda into its only caller.
Swift SVN r10981
2013-12-07 07:10:54 +00:00
Chris Lattner
c1b30b86f4 remove CleanupDestructorSelf, which was only used by now-removed
destructor logic for dancing around self issues.


Swift SVN r10979
2013-12-07 05:53:58 +00:00
Chris Lattner
db0fe52b65 Introduce a new CaptureKind::Constant concept to SILGen, allowing it
to correctly form closures over 'constant' VarDecls like 'self' in 
some cases.


Swift SVN r10978
2013-12-07 05:48:59 +00:00
Adrian Prantl
97ce2b1845 Debug info: Emit dbg.values for self arguments without explicit storage
(such as in destructors).
Fixes <rdar://problem/15609657> No debug info for self in some cases.

Swift SVN r10975
2013-12-07 03:08:22 +00:00
Chris Lattner
dec95a6890 At Joe's request, rename CaptureKind::Constant ->
CaptureKind::LocalFunction, and LocalConstants -> LocalFunctions


Swift SVN r10965
2013-12-07 01:25:30 +00:00
Chris Lattner
0e271de509 introduce a new kind of VarLoc to SILGen: "constant". This
is used for VarDecls that are immutable once defined.  This 
will eventually be used to model 'val' in SILGen, but for now
we can use it to optimize some 'self' situations.

At present, we use it for class 'self' in destructors and for
init methods of root classes.  The init methods of derived 
classes need to be able to mutate self when calling super.init
so they can't use this presently.  I haven't gotten around to
switching general methods to use it yet.

This introduces two new regressions that don't appear in the
testsuite: we lose debug info for "self" in this case, and 
we cannot close over self.



Swift SVN r10962
2013-12-07 01:13:55 +00:00
Joe Groff
27d96bbdc9 SIL: Generalize archetype_method to accept concrete types.
Allow archetype_method to look up a witness from a concrete ProtocolConformance record. This will allow generic specialization to apply to constrained generic functions independent of archetype_method devirtualization. <rdar://problem/14748543>

Swift SVN r10950
2013-12-07 00:00:51 +00:00
Chris Lattner
5c8e9bc070 split SILGenFunction & SGFContext out to a new header, to trim down SILGen.h
to being global stuff.


Swift SVN r10926
2013-12-06 18:40:20 +00:00
Joe Groff
0ff977d407 Add a 'WitnessMethod' enumerator to AbstractCC.
We'll use this to represent the slightly-different polymorphic calling convention used for passing Self into protocol witnesses.

Swift SVN r10898
2013-12-06 01:32:35 +00:00
Adrian Prantl
2055386e0c Debug Info: Move the argument ordering logic into IRGenSILFunction and
get rid of the hack that used to be in IRGenDebugInfo.
This commit also adds a bunch of interesting testcases for function args.
Fixes <rdar://problem/15464454> Arguments sometimes go missing.

Swift SVN r10873
2013-12-05 18:51:07 +00:00
Chris Lattner
ba5351a761 remove the "allOfThis" initialized logic, which is dead now that
structs and enums are handled by DI.  You can't assign to self in 
a class ctor (not currently rejected, but presumably will be when
we have 'val').


Swift SVN r10871
2013-12-05 18:37:40 +00:00
Chris Lattner
c69c069d87 Enhance sema to know to never give imported C structs a default initializer,
they should always use their memberwise init method.

DI now handles all structs.


Swift SVN r10868
2013-12-05 18:24:16 +00:00
Chris Lattner
cdbeb696bb Turn on DI for struct init methods!
- Change silgen to generate mark_unintialized so DI does its thing.
 - Change Sema to not generate an init() method if some stored member has no initial value.
 - Change Sema to disable its horrible horrible heuristic that scans init() bodies to try to decide whether members are initialized. 
 - This doesn't handle structs imported from clang yet.



Swift SVN r10841
2013-12-05 01:56:47 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
Doug Gregor
627f0ae447 Allow "x as T" to perform implicit conversions from x to T.
Fixes <rdar://problem/15283100>.


Swift SVN r10783
2013-12-04 17:31:44 +00:00
Chris Lattner
3289b6e455 Start emitting "mark_unitialized [rootself]" for the self argument of
enum ctors, and add minimal updates to DI to tolerate this.  Doing so 
exposed a bug that would cause DI to crash handling conditional 
destruction of mark_unintialized (which was never possible
before since globals aren't destructed).



Swift SVN r10778
2013-12-04 06:13:35 +00:00
Chris Lattner
567a3175dc extend the mark_initialized SIL instruction to have a "kind" enum field.
Existing uses use a "globalvar" kind.  Add a new "rootinit" kind which
will be used for root initializers (i.e. init methods of structs, enums, 
and root classes).



Swift SVN r10772
2013-12-04 02:02:15 +00:00
John McCall
007d3974d6 Use a proper mangling to try to share reabstraction thunks.
Swift SVN r10764
2013-12-03 23:23:52 +00:00
Chris Lattner
aeddc57297 enable definite init for generic enums initializers as well.
Swift SVN r10733
2013-12-02 22:11:05 +00:00
Chris Lattner
5061ee57a8 stop emitting initialize_var instructions in enum constructors. This is
all we need to enable DI for enum constructors.  Structs and classes are
more complex, and the diagnostic produced is not great.  This resolves 
rdar://14922277.

Also, now an unreachable code diagnostic (with no source location) is 
produced when building the stdlib.  I'll investigate.


Swift SVN r10725
2013-12-02 17:35:38 +00:00
Dave Zarzycki
8bd3582d3e 15242776 stdlib: rename Slice to Array
The "HArray" name is temporary.

Swift SVN r10707
2013-12-01 08:16:30 +00:00
Chris Lattner
ad05efc481 Redesign the BuiltinFunctionRefInst to contain an Identifier instead of
a FuncDecl.  This makes it much more straight-forward for SIL passes to
introduce a new one - without doing name lookup in the builtin module!



Swift SVN r10694
2013-11-30 01:49:36 +00:00
Chris Lattner
3b954ed44d strength reduce SILGenModule::getBuiltinInfo/getIntrinsicInfo to
take an identifier instead of a FuncDecl.


Swift SVN r10692
2013-11-30 00:57:46 +00:00
John McCall
4bba9b38f8 Make several new interfaces traffic in AbstractionPatterns.
Swift SVN r10621
2013-11-21 02:19:46 +00:00
Adrian Prantl
a3960c4299 silentium!
Swift SVN r10617
2013-11-21 00:50:52 +00:00
Chris Lattner
07ce5306f3 add a SILType::isTrivial helper function.
Swift SVN r10610
2013-11-20 22:53:49 +00:00
Adrian Prantl
b3606333b5 Fix a compile error in release mode.
Swift SVN r10579
2013-11-20 03:38:19 +00:00
John McCall
61360de731 Reabstract scalar arguments correctly in normal argument
emission.

Swift SVN r10572
2013-11-20 00:43:48 +00:00
Doug Gregor
84cf9d1183 Cope with local functions within a generic context that have no captures.
Previously, we were just ignoring the generic parameters. Should
finish off <rdar://problem/15463549>.


Swift SVN r10570
2013-11-20 00:01:19 +00:00
Doug Gregor
8c2cc825d5 Mangle local property getters/setters as closures.
This is a very narrow fix for <rdar://problem/15463549>, a crash in
mangling affecting LLDB. We should, in general, provide useful
manglings for closures. 


Swift SVN r10566
2013-11-19 23:26:47 +00:00
Joe Groff
fda0b16507 Quell warning about non-virtual destructor.
Swift SVN r10565
2013-11-19 23:24:22 +00:00
Joe Groff
84ab2a47dc SILGen: Peephole physical lvalue-to-lvalue assignments.
When assigning between physical lvalues, emit a 'copy_addr' instead of a load + assign sequence. This provides a higher-level semantic instruction to SIL passes, and also produces better code in many cases.

It unfortunately exposes another bug in DI which affects the test/IRGen/objc.swift test, which I've XFAILed until it can be fixed.

Swift SVN r10564
2013-11-19 23:17:55 +00:00
Doug Gregor
2f8a60d718 Silence a warning.
Swift SVN r10563
2013-11-19 23:15:37 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
f6b1745650 SIL: Remove 'ModuleInst'.
Module values could never be used for anything, and we have SILUndef now, so when SILGen sees a ModuleExpr, we can just emit 'undef'.

Swift SVN r10548
2013-11-18 21:36:08 +00:00
Joe Groff
f09950390c SILGen: Don't expect an override for declarations from class extensions.
If a subclass overrides a declaration from an ObjC class extension, that decl won't have a vtable entry, and we shouldn't expect to override it. Fixes <rdar://problem/15282548>.

Swift SVN r10547
2013-11-18 21:00:18 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Joe Groff
7b9f61de5c SILGen: Emit global var decl refs as calls to the accessor.
Route global var refs (except for those referencing top-level code vars) through the lazy-initializing global accessor functions for those globals.

Swift SVN r10519
2013-11-16 23:52:39 +00:00
Joe Groff
a049ee9d38 SILGen: (Optionally) emit lazy initializers and accessor fns for globals.
For every global pattern binding, emit a lazy initializer token and function that initializes the global variables in that binding. For each of those vars, create an accessor that Builtin.once's the lazy initializer before producing the address. Hide this all behind a switch till the surrounding serialization and IRGen infrastructure catches up.

Swift SVN r10511
2013-11-16 00:50:19 +00:00
Adrian Prantl
07bdac2c12 silence warning
Swift SVN r10505
2013-11-15 23:24:47 +00:00
Joe Groff
e75ca8bef3 AST: Improve modeling of static property references.
Instead of cutting corners by emitting a static property reference as a DeclRef, do the right thing and build a MemberRef on the metatype. Add the smarts to SILGen to recognize static property MemberRefs and emit global_addr instructions for (nongeneric, nondynamic) static properties.

Swift SVN r10482
2013-11-15 01:00:44 +00:00
Joe Groff
19457c12ea Give Builtin.Word an abstract size.
Instead of hardcoding Builtin.Word to be an alias for Builtin.Int64, make it its own type of abstract pointer width.

- Change BuiltinIntegerType's width representation to accommodate abstract widths.

- In the AST and in SIL, store values of the types as the greatest supported size for the abstract width (64 bits for a pointer).

- Add some type safety to the ([sz]ext|trunc)(OrBitCast)? builtins that they're used appropriately given the upper and lower bounds of the abstract sizes they're working with.

- Now that Builtin.Word is a distinct type, give it its own mangling.

- In IRGen, lower pointer-sized BuiltinIntegerType appropriately for the target, and truncate lowered SIL values if necessary.

Fixes <rdar://problem/15367913>.

Swift SVN r10467
2013-11-14 19:56:26 +00:00
John McCall
08171453da Make it a bit easier to propogate expressions around instead
of having to lower to an RValue.

This is valuable because we can often emit an expression to a
desired abstraction level more efficiently than just emitting
it to minimal abstraction and then generalizing.

Swift SVN r10455
2013-11-14 05:25:06 +00:00
Chris Lattner
4968cc208b A couple of related changes:
- Enhance SILBuilder::emitStrongRelease to be smarter.
- Start using emitStrongRelease in type lowering, SILGen,
  CapturePromotion (replacing its implementation of the
  same logic), and MandatoryInlining (one more place)
- Rename the primitive createStrongRetain/ReleaseInst
  instructions to lose their suffix.
- Now that createStrongRetain/ReleaseInst are not special
  cases from the naming perspective, remove some special cases
  from DeserializeSIL and ParseSIL.
  


Swift SVN r10449
2013-11-14 02:21:27 +00:00
Chris Lattner
9570e1fb0c Remove the "createStrongRetain" and "createStrongRelease" SILBuilder methods.
They are the same as createStrongRetainInst and createStrongReleaseInst, but
peephole away FunctionRefInst.  It turns out that there is only a couple
places in SILGen where this behavior is necessary, and this tramples on the
general pattern used in SILBuilder.


Swift SVN r10448
2013-11-14 02:00:41 +00:00