Skip to content

RequirementMachine: Convert to new assertions #74631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 22, 2024

Conversation

slavapestov
Copy link
Contributor

No description provided.

@slavapestov slavapestov force-pushed the rqm-assertions branch 2 times, most recently from d558624 to db7fa8c Compare June 21, 2024 20:15
@slavapestov slavapestov force-pushed the rqm-assertions branch 2 times, most recently from 21ea00b to fcc0702 Compare June 21, 2024 20:25
@@ -43,7 +43,7 @@

#define ASSERT(expr) \
do { \
if (ASSERT_UNLIKELY(!expr)) { \
if (ASSERT_UNLIKELY(!(expr))) { \
Copy link
Contributor

Choose a reason for hiding this comment

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

Ouch. Good catch!

ASSERT(!props->isConcreteType() &&
"Concrete types do not have conformance access paths");
auto conformsTo = props->getConformsTo();
CONDITIONAL_ASSERT(std::find(conformsTo.begin(), conformsTo.end(), protocol) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Not much point to having CONDITIONAL_ASSERT inside a CONDITIONAL_ASSERT_enabled block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch.

auto prefixBegin = lookupTerm.begin();
auto prefixEnd = lookupTerm.end() - Key.size();
assert(std::equal(prefixEnd, lookupTerm.end(), Key.begin()) &&
"This is not the bag you're looking for");
DEBUG_ASSERT(std::equal(prefixEnd, lookupTerm.end(), Key.begin()) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Why DEBUG_ASSERT here? (Genuinely curious.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed that in a few places the asserts are extremely defensive because the caller establishes the condition immediately... but maybe that line of reasoning defeats the purpose of asserts!

I also used DEBUG_ASSERT in a few 'inner loops'. I was going to profile this patch anyway so I can play around with things a bit to see where we stand.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for that clarification. It helps to hear people talk about how they think of these things.

@tbkka
Copy link
Contributor

tbkka commented Jun 21, 2024

I'm curious about the use of DEBUG_ASSERT -- I had expected it to get used very rarely if at all, but you use it a few times here, so I'd like to understand the usage better.

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit bf1d174 into swiftlang:main Jun 22, 2024
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.

2 participants