Skip to content

Conversation

asl
Copy link
Contributor

@asl asl commented Feb 5, 2023

The changes are intentionally were made close to the original implementation w/o possible simplifications to ease the review

Fixes #63207, supersedes #63379 (and fixes #63234)

@asl asl requested a review from rxwei February 5, 2023 21:55
@asl
Copy link
Contributor Author

asl commented Feb 5, 2023

Tagging @BradLarson @dan-zheng

@asl
Copy link
Contributor Author

asl commented Feb 5, 2023

@swift-ci please test

@dan-zheng
Copy link
Contributor

Nice approach! This seems to simplify things and avoids the struct complications.

I wonder if there are still complications from the branching trace enums, since those are still NominalTypeDecls who go through various verifications – but that would be separate.

@asl
Copy link
Contributor Author

asl commented Feb 5, 2023

@dan-zheng Yes. I'm afraid we can still cook a testcase that would trigger an assertion similar to #63207 but due to lack of imported branch trace enum type. Though, I believe it must be more complicated.

if (!origBB.isEntry()) {
CanType traceEnumType = getBranchingTraceEnumLoweredType(&origBB).getASTType();
linearTupleTypes.emplace_back(traceEnumType,
astCtx.getIdentifier(traceEnumFieldName));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... wait I don't think SIL tuples are allowed to have labels, as it's no longer a canonical type? Am I misremembering this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it seems it does not cause any problems anywhere, the identifier is just stored in the type and that's it. I double checked – the generated SIL parses as well.

On the other hand – having named field for branch trace enum helps debugging as we're having internal contract with indices :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Something unrelated: would it be better if we made the branching trace enum be the last element? Might help with alignment in the tuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly speaking, I do not know :) I wanted to replicate the struct layout to minimize possible unknown fallback. This is certainly worth exploring if e.g. this might improve the codegen, etc.

@@ -3433,6 +3433,36 @@ static void printSILDifferentiabilityWitnesses(
dw->print(Ctx.OS(), Ctx.printVerbose());
}

static void printSILLinearMapTypes(SILPrintContext &Ctx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only for printing branching trace enums now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super exciting! For branching trace enums, perhaps we should explore adding a SIL-level sum type construct. Then we may be able to remove SynthesizedFileUnit altogether because it was added just for AD-generated types.

@asl
Copy link
Contributor Author

asl commented Feb 6, 2023

This is super exciting! For branching trace enums, perhaps we should explore adding a SIL-level sum type construct. Then we may be able to remove SynthesizedFileUnit altogether because it was added just for AD-generated types.

Yeah, right. But maybe as a next step? :)

@rxwei
Copy link
Contributor

rxwei commented Feb 6, 2023

Sure, this is already strictly an improvement.

@asl
Copy link
Contributor Author

asl commented Feb 7, 2023

@swift-ci please test

@asl
Copy link
Contributor Author

asl commented Feb 7, 2023

@rxwei I'm feeling like opening a can of worms as many things require original AST types, while we'd need to operate mostly on lowered SIL ones :) I thought that I fixed all such places, but apparently not. The last failure was caused by assertion inside generic cloner as metatype instruction (which is used when we'd need to allocate linear map context in loopy cases) essentially requires AST type... And this could only be triggered in optimized build.

@asl asl force-pushed the linear-map-tuple branch from db9317b to 6aa558b Compare February 7, 2023 15:43
@asl
Copy link
Contributor Author

asl commented Feb 7, 2023

@swift-ci please test

@asl
Copy link
Contributor Author

asl commented Feb 7, 2023

MacOS test is broken due to broken main after #63423

@asl asl force-pushed the linear-map-tuple branch from 6aa558b to 20c1edc Compare February 7, 2023 17:45
@asl
Copy link
Contributor Author

asl commented Feb 7, 2023

@swift-ci please test

@asl
Copy link
Contributor Author

asl commented Feb 7, 2023

@swift-ci please test macos platform

1 similar comment
@asl
Copy link
Contributor Author

asl commented Feb 8, 2023

@swift-ci please test macos platform

@asl asl merged commit d2e022d into swiftlang:main Feb 8, 2023
@asl asl deleted the linear-map-tuple branch February 8, 2023 15:42
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.

AutoDiff produces SIL that cannot be read back Type reconstruction fails for some @differentiable functions when unit tests are built for Profiling.
3 participants