Commit graph

275 commits

Author SHA1 Message Date
Luna
82878ef32c
Improve Objective-C support (#4777)
* WIP: Objective-C support

* Further work on implementation

* ObjC dynamic cast

* Add swift stub class attribute

* Classes, protocols and ivars

* Fix compilation issues

* Fix objc ir codegen

* Add objc linker option

* Add swift stub classref get ir gen

* Minor cleanup

* Fix objc link flag being added on non-darwin platforms

* Refactor objc gen

* remove use of std::nullopt

* Emit protocol tables

* Remove unused variable

* Formatting

* Fix build in release mode. Thanks for nothing, c++.

* Fix consistency

* Fix dynamic casts

* Fix tocall parentfd ref and arm msgsend call

* Make instance variables work

* Implicitly add isa pointer to objc classes.

* Fix protocol referencing & allow pragma mangle

* Fix protocol linkage

* Fix direct call support

* always generate var type for methods

* Fix test 16096a

* Fix extern ivar symbol gen, retain method decls

* Remove arm32 and x86 support

* Check method and ivar info before pushing to member list

* Make ObjcMethod info untyped.

* Make ivar and method gen more robust

* Generate optional protocol symbols

* Use bitcasting instead of creating multiple type defs

* Fix invalid protocol list struct gen

* More codegen robustness

* emit protocol table as const

* Make protocol table anon struct

* Fix callable type, generate protocol_list_t properly.

* Cast vthis to argtype

* Handle protorefs and classrefs properly

* seperate label ref and deref

* Fix method lookup

* Enable objective-c tests

* Enable objc_call_static test

* Scan both classes and protocols for method ref

* Enable objective-c tests on arm as well.

* supress objc linker warning in tests

* Fix class and protocol gen structure

* Fix objc_protocol_sections test

* ObjcMethod only get callee for functions with bodies

* Fix protocol class method gen

* Make ObjcMethod anon again

* Fix missing emit calls

* Fix classref gen

* Implement some of the requested changes

* Enable compilable tests

* Fix property selector gen, ugly hack for final funcs.

* Fix segfault in referencing fd->type

* Refactor implementation

* Fix null references in class and method lookup

* include unordered_map

* Get functionality on-par with prev impl.

* Fix super context calls

* Move -L-w flag to d_do_test and use IN_LLVM in objc.d/h

* add LDC version tag to -L-w flag

* Update CHANGELOG.md
2024-12-03 04:26:27 +01:00
Martin Kinkelin
0c1623c1a0 Replace getVoidPtrType() 2024-07-18 23:21:10 +02:00
Martin Kinkelin
a37c2ab5f0 Get rid of now unused variables 2024-05-20 17:48:59 +02:00
Martin Kinkelin
d140f2a283 Skip superfluous IR pointer bitcasts, now that they are always opaque 2024-05-20 16:45:09 +02:00
Johan Engelen
bc00d4b775
Add memory invariant assumptions for virtual calls to improve devirtualization (#4596)
Assumptions:
- class methods do not change the object's vtable pointer
- loads through vtable pointer are invariant (vtables are immutable throughout program life)
2024-04-05 16:14:38 +02:00
Martin Kinkelin
5f46c65ab5
Fix v1.31 regression wrt. unresolved IrAggr (#4312)
And use `IrTypeClass::getVtblType()` to get the vtable LLVM array
type, instead of deriving it from the `IrClass::getVtblSymbol()`
global (invoking that function may define the vtable!).

I've hit some compiler crashes for the Symmetry code base, on
Windows only. I guess the problem surfaced due to
`-link-defaultlib-shared`, which on Windows causes some vtables of
instantiated classes to be defined whenever accessing the vtable
symbol. I don't have a reduced test case unfortunately.
2023-02-06 17:02:07 +01:00
Martin Kinkelin
153f8ccdce Fix regression for LDC-specific elide-scope-class-finalization optimization
`NewExp.type` can apparently newly be a yet-unresolved `TypeIdentifier`.
Resolve it in that case to a `TypeClass` now.

Also defer the has-dtor check for the whole class hierarchy of the
*dynamic* type from that LDC-specific frontend addition to the glue
layer, as I'm not sure we can rely on `ClassDeclaration.dtor` having
been set at that time already.

I've chosen to keep storing a single extra LDC-specific *bit*
(`onstackWithMatchingDynType`) instead of storing the full dynamic
class type. While this slightly weakens the optimization (no
optimization for non-equivalent static/dynamic class types anymore),
it doesn't increase the AST node size. And I think almost all cases
use an equivalent type anyway (e.g., the DMD frontend itself only uses
`scope` class allocations with equivalent types).
2023-01-21 18:38:28 +01:00
Nicholas Wilson
25ccb6fd18
Remove getContainedType from classes.cpp (#4156) 2022-09-13 20:37:59 +08:00
Nicholas Wilson
bdd647c558
Remove getContainedType from classes.cpp (#4152) 2022-09-13 19:54:25 +08:00
Nicholas Wilson
fc71e6a937
Use typed gep in classes.cpp (#4091)
This logic should be merge with toir.cpp:visit(TypeidExp *e)
2022-09-01 17:15:13 +08:00
Nicholas Wilson
d8d105fb1b
Use typed gep in DtoFinalizeScopeClass (#4081) 2022-08-31 11:14:23 +08:00
Nicholas Wilson
a79a30c41e
Use typed gep in DtoCastClass (#4082) 2022-08-31 10:50:20 +08:00
Nicholas Wilson
68ae4352ab
Use typed gep in classes.cpp (#4079) 2022-08-31 09:51:33 +08:00
Nicholas Wilson
aea2033c19
Remove getPointeeType from DtoAlignedLoad (#4025) 2022-08-21 08:24:40 +08:00
Martin Kinkelin
7b6810b01b Fix LLVM 13 deprecation messages during build 2022-02-26 19:15:46 +01:00
Martin Kinkelin
65fe0cb9f2 Merge upstream stable (dlang/dmd@58e4db9880) 2021-10-18 17:50:28 +02:00
Martin Kinkelin
86f430c039 Slightly revise frontend diff
E.g., preferring local imports for less merge conflict potential.
2021-09-11 17:34:51 +02:00
Martin Kinkelin
e9f40d8a1a Adapt to removed custom (de)allocators 2021-09-07 16:51:19 +02:00
Martin Kinkelin
369cfd13ce Adapt to TY enum class 2021-09-07 16:51:19 +02:00
Martin Kinkelin
a9aafac862 Glue layer: Make all mutable Loc & params const 2020-12-13 15:01:19 +01:00
Martin Kinkelin
3f452646f5 Refactor generation of interface vtbls for classes 2020-10-24 20:07:29 +02:00
Martin Kinkelin
96b9cde428 Add support for LLVM 11
One major change is the removal of llvm::CallSite, which I've replaced
by llvm::CallBase*.
2020-09-26 01:04:50 +02:00
Martin Kinkelin
69269f3bd9 Refactor IRScope handling
Replace the stack of IRScopes, each with its own IRBuilder, by directly
tampering with the state of a single IRBuilder.

This seems like the most feasible way to account for a breaking change
in LLVM 11, disallowing IRBuilder from being copied.
2020-09-26 01:04:50 +02:00
Martin Kinkelin
9e8111738b
Simplify IR names of virtual function pointers (#3534)
This works around #3526 (but makes sense in general IMO).
For that testcase, the v1.22 IR was:

  %"(bar() , foo)().length@vtbl" = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i32 0, i32 5 ; [#uses = 1, type = i8**]
  %5 = load i8*, i8** %"(bar() , foo)().length@vtbl", align 8 ; [#uses = 1]
  %"(bar() , foo)().length" = bitcast i8* %5 to i64 (%current.Foo*)* ; [#uses = 1]
  %6 = call x86_vectorcallcc i64 %"(bar() , foo)().length"(%current.Foo* nonnull %2) ; [#uses = 1]

Now it's:

  %"length@vtbl" = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i32 0, i32 5 ; [#uses = 1, type = i8**]
  %5 = load i8*, i8** %"length@vtbl", align 8     ; [#uses = 1]
  %length = bitcast i8* %5 to i64 (%current.Foo*)* ; [#uses = 1]
  %6 = call x86_vectorcallcc i64 %length(%current.Foo* nonnull %2) ; [#uses = 1]
2020-08-08 17:04:04 +02:00
Martin Kinkelin
49affcffb2
Fix issue #3496 - missing IR declarations for some fwd-declared functions (#3503)
Whenever we need an IR function, we'd better make sure it exists. Handle
that in DtoCallee(), by invoking DtoDeclareFunction() by default,
instead of the previous DtoResolveFunction() + DtoCallee() combo.
DtoResolveFunction() usually declares the function, but somehow doesn't
for abstract and body-less functions.
2020-07-13 21:49:41 +02:00
Martin Kinkelin
c09f7ed617 Revise struct/class/interface TypeInfo generation, incl. getting rid of GENERATE_OFFTI
I've also compared against the current DMD implementations, to make sure
we are in sync.

DMD doesn't populate `TypeInfo_Class.m_offTi` either. This seems like a
leftover of some unimplemented idea (the LDC commit introducing the
CMake option is from 2008); the normal `TypeInfo_Class.interfaces` array
contains the offsets nowadays.
2020-07-04 16:42:52 +02:00
Martin Kinkelin
ab619744f2 Refactoring: Specialize IrAggr into IrStruct and IrClass
And move ClassInfo generation from gen/classes.cpp to ir/irclass.cpp.
2020-07-01 21:28:45 +02:00
Martin Kinkelin
770383c3e7 Upgrade frontend & libs to early v2.091.0 (dlang/dmd@44112eb84b) 2020-02-22 00:33:49 +01:00
Etienne Cimon
40914dc23f
Fix wrong assertion wrt. virtual function vtbl index (#3327)
Fixes #3324 by checking the aggregate linkage, not the function's, for special vtbl index 0.
2020-02-16 23:29:48 +01:00
Martin Kinkelin
4ac7f0554b Adapt to frontend refactorings 2019-12-22 16:29:45 +01:00
Martin Kinkelin
8fd69da8fb Make all DtoGEP helpers use implicit inbounds
Single functional change: always emit inbounds when computing the base
pointer of a SliceExp.
2019-09-10 22:36:25 +02:00
Martin Kinkelin
e52199469f Upgrade front-end & libs to v2.087.0-beta.1 2019-06-21 15:39:45 +02:00
Martin Kinkelin
ef2bbfa09b Fix DIP1008
Invoke _d_newThrowable for exception allocation & initialization, and
increase the reference count in LDC-specific _d_throw_exception for MSVC
targets. Fixes runnable/test19317.d.
2019-04-25 22:16:20 +02:00
Martin Kinkelin
b3b06d0cc7 Replace LDC-specific VarDeclaration.scopeClassType by .onstackWithDtor
This doesn't increase the VarDeclaration size.
2019-04-13 20:34:16 +02:00
Martin Kinkelin
5e93ed0dfd Upgrade front-end & libs to v2.085.0-beta.1 2019-03-01 18:19:00 +01:00
Martin Kinkelin
ab38d73b26 Fix alignment of scope-allocated class instances
I noticed that an `align(N) class ...` seems to be totally ignored; i.e.,
it has no effect on `Type::alignment()` and neither on
`ClassDeclaration::alignsize()`.

I checked the paddings too (and the tests cover them as well); they seem
fine already, both inbetween header and payload (and for both D and C++
classes, the latter missing the monitor field) as well as inbetween base
payload and derived payload.
2018-11-19 21:50:40 +01:00
Martin Kinkelin
4a23399236 Aim for consistent #includes (order + dir prefix)
I surely missed a few.
2018-10-20 16:19:46 +02:00
Martin Kinkelin
7776c4081b Upgrade frontend & libs to v2.083.0-beta.1 2018-10-20 16:19:46 +02:00
Martin Kinkelin
267ffbb645
Posix: Fix C++ class construction with D new (#2801) 2018-08-31 16:37:24 +02:00
Martin Kinkelin
40cf784cbe Misc. merge fixes, minor adaptions 2018-08-17 21:31:53 +02:00
Martin Kinkelin
494bc8b1e4
Add some support for classes without TypeInfos (#2765)
For -betterC and/or a minimal object.d without TypeInfo:

* Skip TypeInfo emission for classes and interfaces.
* Emit null as first vtable member.

Makes dmd-testsuite's {compilable,runnable}/minimal2.d work.
2018-07-10 17:56:05 +02:00
Martin Kinkelin
7dbd07dd1e Use new extern(D) dtor shims for struct/class TypeInfos
The TypeInfo may need an extern(D) wrapper accounting for ABI
differences wrt. extern(C++) dtor implementations.

This fixes `runnable/cppa.d` for 32-bit x86 targets.
2018-06-23 19:31:43 +02:00
Martin
e337cec78a Slightly refactor RTTIBuilder 2018-04-04 19:59:10 +02:00
Martin
9ff736bf0f Lookup runtime function before constructing the call args
To retain the LoC information in case TypeInfo declarations are missing.
2018-04-04 19:59:10 +02:00
Martin
d8f60d2f5c Redirect access to object.d type declarations through gen/runtime
Not all type declarations yet (e.g., some TypeInfo subtypes are still
accessed directly), but those already wrapped as LazyType in the
gen/runtime.cpp module (with check and proper error msg in case object.d
doesn't contain a required declaration).
2018-04-04 19:59:10 +02:00
Martin
1b860e70d7 Merge branch 'master' into merge-2.078 2018-01-26 18:52:49 +01:00
Martin Kinkelin
6367d98d3a
Don't finalize scope objects without dtors and monitor (#2516)
The dtors can be checked at compile-time; insert a runtime check for the
monitor before finalizing the stack-allocated class object via druntime
call.

See issue #2515.
2018-01-26 18:38:16 +01:00
Martin
bd1db42ca0 Fix transition from removed ClassDeclaration::cpp 2018-01-06 15:03:24 +01:00
Martin
cfad799f48 Merge 2.078.0 front-end and stdlibs 2018-01-06 01:39:18 +01:00
kinke
d1b30d627c Backport fix for issue #2357 (#2366)
Improve robustness for TypeInfos of speculative types by only eliding
their TypeInfo definition, not the declaration of the LL global
altogether.

`DtoTypeInfoOf()` expects the LL global to be created and otherwise
fails with an assertion or segfault (e.g., issue #2357). So now only
linker errors should result in case the TypeInfo definition is missing.

Also normalize the calls to `DtoTypeInfoOf()` and revise the following
pointer bitcasts, as the LL type of forward-declared TypeInfo globals
may be opaque.
2017-10-18 20:47:09 +02:00