Skip to content

Conversation

@0xLucasMarcal
Copy link
Contributor

This pull request modernizes the Swinject codebase by removing code generation, adopting Swift's pack iteration, and refactoring several APIs for improved flexibility and maintainability. The changes simplify argument and type forwarding handling, eliminate repetitive boilerplate, and update the build process accordingly.

Migration to variadic generics and API simplification

  • Replaced all manually-generated overloads for resolving services with variadic generics in the Resolver protocol and Container implementation, allowing any number of arguments to be passed without code generation. (Sources/Resolver.swift, Sources/Container.swift) [1] [2] [3]
  • Refactored the ServiceEntry type forwarding API to use variadic generics, replacing multiple overloads with a single method that forwards any number of types. (Sources/ServiceEntry.TypeForwarding.swift)

Removal of code generation and legacy files

  • Deleted the code generation script and references to generated files, as variadic generics make manual generation unnecessary. (script/gencode, Sources/Container.Arguments.erb, comments in source files) [1] [2] [3] [4]

These changes make Swinject easier to maintain, more idiomatic to modern Swift, and remove the need for boilerplate code and build scripts.

Why is this a draft?

The compiler is not stable enough to properly support this feature, this PR's code causes a compile-time crash:

1.	Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/lucasmarcal/faire/Swinject/Sources/Container.swift")
4.	While generating SIL witness table protocol conformance Container: Resolver at extension of Container (at /Users/lucasmarcal/faire/Swinject/Sources/Container.swift:370:1)
5.	While generating protocol witness thunk SIL function "@$s8Swinject9ContainerCAA8ResolverA2aDP7resolve_8argumentqd__Sgqd__m_qd_0_qd_0_Qp_ttRvd_0_r0_lFTW".
 for 'resolve(_:argument:)' (at /Users/lucasmarcal/faire/Swinject/Sources/Container.swift:440:12)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010b1cee24 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010b1ccc5c llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010b1cf460 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x00000001845e96a4 _sigtramp + 56
4  swift-frontend           0x0000000105ba1ccc (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 6888
5  swift-frontend           0x0000000105badd38 (anonymous namespace)::TranslateArguments::processSingleInto(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::Initialization&) + 128
6  swift-frontend           0x0000000105bae0dc (anonymous namespace)::TranslateArguments::processIndirect(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::ManagedValue, (anonymous namespace)::ParamInfo) + 192
7  swift-frontend           0x0000000105bad83c (anonymous namespace)::TranslateArguments::processSingle(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::ManagedValue, (anonymous namespace)::ParamInfo) + 736
8  swift-frontend           0x0000000105ba3910 (anonymous namespace)::TranslateArguments::process(swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, bool) + 2516
9  swift-frontend           0x0000000105ba6a44 swift::Lowering::SILGenFunction::emitProtocolWitness(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILDeclRef, swift::SubstitutionMap, swift::SILDeclRef, swift::SubstitutionMap, swift::Lowering::IsFreeFunctionWitness_t, bool, bool, std::__1::optional<swift::ActorIsolation>) + 2724
10 swift-frontend           0x0000000105bddd94 swift::Lowering::SILGenModule::emitProtocolWitness(swift::ProtocolConformanceRef, swift::SILLinkage, swift::SerializedKind_t, swift::SILDeclRef, swift::SILDeclRef, swift::Lowering::IsFreeFunctionWitness_t, swift::Witness) + 4336
11 swift-frontend           0x0000000105be0a9c (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethodImplementation(swift::SILDeclRef, swift::SILDeclRef, swift::Witness) + 428
12 swift-frontend           0x0000000105be05b0 (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethod(swift::SILDeclRef) + 1080
13 swift-frontend           0x0000000105bdff98 swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 1760
14 swift-frontend           0x0000000105bdc850 swift::Lowering::SILGenModule::getWitnessTable(swift::NormalProtocolConformance*) + 548
15 swift-frontend           0x0000000105bdf7cc SILGenExtension::emitExtension(swift::ExtensionDecl*) + 824
16 swift-frontend           0x0000000105a87168 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 308
17 swift-frontend           0x0000000105a8dce0 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1568
18 swift-frontend           0x0000000105bc6f50 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 208
19 swift-frontend           0x0000000105a9286c swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 728
20 swift-frontend           0x0000000105020064 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 968
21 swift-frontend           0x0000000105023654 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
22 swift-frontend           0x0000000105021fd8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3716
23 swift-frontend           0x0000000104fa60bc swift::mainEntry(int, char const**) + 5428
24 dyld                     0x000000018420eb98 start + 6076
Failed frontend command:
/Applications/Xcode-16-4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant