@@ -383,45 +383,51 @@ static std::pair<Symbol, bool> unifySuperclasses(
383
383
return std::make_pair (rhs, false );
384
384
}
385
385
386
- // / Returns the old conflicting rule ID if there was a conflict,
387
- // / otherwise returns None.
388
- Optional<unsigned > PropertyBag::addProperty (
389
- Symbol property, unsigned ruleID, RewriteSystem &system,
390
- SmallVectorImpl<InducedRule> &inducedRules,
391
- bool debug) {
386
+ // / Record a protocol conformance, layout or superclass constraint on the given
387
+ // / key. Must be called in monotonically non-decreasing key order.
388
+ // /
389
+ // / If there was a conflict, returns the conflicting rule ID; otherwise
390
+ // / returns None.
391
+ Optional<unsigned > PropertyMap::addProperty (
392
+ Term key, Symbol property, unsigned ruleID,
393
+ SmallVectorImpl<InducedRule> &inducedRules) {
394
+ assert (property.isProperty ());
395
+ assert (*System.getRule (ruleID).isPropertyRule () == property);
396
+ auto *props = getOrCreateProperties (key);
397
+ bool debug = Debug.contains (DebugFlags::ConcreteUnification);
392
398
393
399
switch (property.getKind ()) {
394
400
case Symbol::Kind::Protocol:
395
- ConformsTo.push_back (property.getProtocol ());
396
- ConformsToRules.push_back (ruleID);
401
+ props-> ConformsTo .push_back (property.getProtocol ());
402
+ props-> ConformsToRules .push_back (ruleID);
397
403
return None;
398
404
399
405
case Symbol::Kind::Layout: {
400
406
auto newLayout = property.getLayoutConstraint ();
401
407
402
- if (!Layout) {
408
+ if (!props-> Layout ) {
403
409
// If we haven't seen a layout requirement before, just record it.
404
- Layout = newLayout;
405
- LayoutRule = ruleID;
410
+ props-> Layout = newLayout;
411
+ props-> LayoutRule = ruleID;
406
412
} else {
407
413
// Otherwise, compute the intersection.
408
- assert (LayoutRule.hasValue ());
409
- auto mergedLayout = Layout.merge (property.getLayoutConstraint ());
414
+ assert (props-> LayoutRule .hasValue ());
415
+ auto mergedLayout = props-> Layout .merge (property.getLayoutConstraint ());
410
416
411
417
// If the intersection is invalid, we have a conflict.
412
418
if (!mergedLayout->isKnownLayout ())
413
- return LayoutRule;
419
+ return props-> LayoutRule ;
414
420
415
421
// If the intersection is equal to the existing layout requirement,
416
422
// the new layout requirement is redundant.
417
- if (mergedLayout == Layout) {
418
- recordRelation (*LayoutRule, ruleID, system , inducedRules, debug);
423
+ if (mergedLayout == props-> Layout ) {
424
+ recordRelation (*props-> LayoutRule , ruleID, System , inducedRules, debug);
419
425
420
426
// If the intersection is equal to the new layout requirement, the
421
427
// existing layout requirement is redundant.
422
428
} else if (mergedLayout == newLayout) {
423
- recordRelation (ruleID, *LayoutRule, system , inducedRules, debug);
424
- LayoutRule = ruleID;
429
+ recordRelation (ruleID, *props-> LayoutRule , System , inducedRules, debug);
430
+ props-> LayoutRule = ruleID;
425
431
} else {
426
432
llvm::errs () << " Arbitrary intersection of layout requirements is "
427
433
<< " supported yet\n " ;
@@ -435,34 +441,34 @@ Optional<unsigned> PropertyBag::addProperty(
435
441
case Symbol::Kind::Superclass: {
436
442
// FIXME: Also handle superclass vs concrete
437
443
438
- if (!Superclass) {
439
- Superclass = property;
440
- SuperclassRule = ruleID;
444
+ if (!props-> Superclass ) {
445
+ props-> Superclass = property;
446
+ props-> SuperclassRule = ruleID;
441
447
} else {
442
- assert (SuperclassRule.hasValue ());
443
- auto pair = unifySuperclasses (*Superclass, property,
444
- system .getRewriteContext (),
448
+ assert (props-> SuperclassRule .hasValue ());
449
+ auto pair = unifySuperclasses (*props-> Superclass , property,
450
+ System .getRewriteContext (),
445
451
inducedRules, debug);
446
- Superclass = pair.first ;
452
+ props-> Superclass = pair.first ;
447
453
bool conflict = pair.second ;
448
454
if (conflict)
449
- return SuperclassRule;
455
+ return props-> SuperclassRule ;
450
456
}
451
457
452
458
return None;
453
459
}
454
460
455
461
case Symbol::Kind::ConcreteType: {
456
- if (!ConcreteType) {
457
- ConcreteType = property;
458
- ConcreteTypeRule = ruleID;
462
+ if (!props-> ConcreteType ) {
463
+ props-> ConcreteType = property;
464
+ props-> ConcreteTypeRule = ruleID;
459
465
} else {
460
- assert (ConcreteTypeRule.hasValue ());
461
- bool conflict = unifyConcreteTypes (*ConcreteType, property,
462
- system .getRewriteContext (),
466
+ assert (props-> ConcreteTypeRule .hasValue ());
467
+ bool conflict = unifyConcreteTypes (*props-> ConcreteType , property,
468
+ System .getRewriteContext (),
463
469
inducedRules, debug);
464
470
if (conflict)
465
- return ConcreteTypeRule;
471
+ return props-> ConcreteTypeRule ;
466
472
}
467
473
468
474
return None;
0 commit comments