|
13 | 13 | #include "swift/SIL/SILFunctionBuilder.h" |
14 | 14 | #include "swift/AST/AttrKind.h" |
15 | 15 | #include "swift/AST/Availability.h" |
16 | | -#include "swift/AST/Decl.h" |
17 | 16 | #include "swift/AST/DiagnosticsParse.h" |
18 | | -#include "swift/AST/DiagnosticsSIL.h" |
19 | 17 | #include "swift/AST/DistributedDecl.h" |
| 18 | +#include "swift/AST/Decl.h" |
20 | 19 | #include "swift/AST/ParameterList.h" |
21 | 20 | #include "swift/AST/SemanticAttrs.h" |
22 | 21 |
|
@@ -61,8 +60,6 @@ void SILFunctionBuilder::addFunctionAttributes( |
61 | 60 | if (auto *A = Attrs.getAttribute(DAK_EmitAssemblyVisionRemarks)) |
62 | 61 | F->addSemanticsAttr(semantics::FORCE_EMIT_OPT_REMARK_PREFIX); |
63 | 62 |
|
64 | | - auto *attributedFuncDecl = constant.getAbstractFunctionDecl(); |
65 | | - |
66 | 63 | // Propagate @_specialize. |
67 | 64 | for (auto *A : Attrs.getAttributes<SpecializeAttr>()) { |
68 | 65 | auto *SA = cast<SpecializeAttr>(A); |
@@ -107,74 +104,21 @@ void SILFunctionBuilder::addFunctionAttributes( |
107 | 104 | } |
108 | 105 | } |
109 | 106 |
|
110 | | - EffectsAttr const *writeNoneEffect = nullptr; |
111 | | - EffectsAttr const *releaseNoneEffect = nullptr; |
112 | 107 | llvm::SmallVector<const EffectsAttr *, 8> customEffects; |
113 | 108 | if (constant) { |
114 | 109 | for (auto *attr : Attrs.getAttributes<EffectsAttr>()) { |
115 | 110 | auto *effectsAttr = cast<EffectsAttr>(attr); |
116 | | - switch (effectsAttr->getKind()) { |
117 | | - case EffectsKind::Custom: |
| 111 | + if (effectsAttr->getKind() == EffectsKind::Custom) { |
118 | 112 | customEffects.push_back(effectsAttr); |
119 | | - // Proceed to the next attribute, don't set the effects kind based on |
120 | | - // this attribute. |
121 | | - continue; |
122 | | - case EffectsKind::ReadNone: |
123 | | - case EffectsKind::ReadOnly: |
124 | | - writeNoneEffect = effectsAttr; |
125 | | - break; |
126 | | - case EffectsKind::ReleaseNone: |
127 | | - releaseNoneEffect = effectsAttr; |
128 | | - break; |
129 | | - default: |
130 | | - break; |
131 | | - } |
132 | | - if (effectsAttr->getKind() == EffectsKind::Custom) |
133 | | - continue; |
134 | | - if (F->getEffectsKind() != EffectsKind::Unspecified) { |
135 | | - // If multiple known effects are specified, the most restrictive one |
136 | | - // is used. |
137 | | - F->setEffectsKind( |
138 | | - std::min(effectsAttr->getKind(), F->getEffectsKind())); |
139 | | - } else { |
140 | | - F->setEffectsKind(effectsAttr->getKind()); |
141 | | - } |
142 | | - } |
143 | | - } |
144 | | - |
145 | | - if (writeNoneEffect && !releaseNoneEffect) { |
146 | | - auto constantType = mod.Types.getConstantFunctionType( |
147 | | - TypeExpansionContext::minimal(), constant); |
148 | | - SILFunctionConventions fnConv(constantType, mod); |
149 | | - |
150 | | - auto selfIndex = fnConv.getSILArgIndexOfSelf(); |
151 | | - for (auto index : indices(fnConv.getParameters())) { |
152 | | - auto param = fnConv.getParameters()[index]; |
153 | | - if (!param.isConsumed()) |
154 | | - continue; |
155 | | - if (index == selfIndex) { |
156 | | - mod.getASTContext().Diags.diagnose( |
157 | | - writeNoneEffect->getLocation(), |
158 | | - diag:: |
159 | | - error_attr_effects_consume_requires_explicit_releasenone_self); |
160 | 113 | } else { |
161 | | - auto *pd = attributedFuncDecl->getParameters()->get(index); |
162 | | - mod.getASTContext().Diags.diagnose( |
163 | | - writeNoneEffect->getLocation(), |
164 | | - diag::error_attr_effects_consume_requires_explicit_releasenone, |
165 | | - pd->getName()); |
166 | | - mod.getASTContext().Diags.diagnose( |
167 | | - pd->getNameLoc(), |
168 | | - diag::note_attr_effects_consume_requires_explicit_releasenone, |
169 | | - pd->getName()); |
| 114 | + if (F->getEffectsKind() != EffectsKind::Unspecified && |
| 115 | + F->getEffectsKind() != effectsAttr->getKind()) { |
| 116 | + mod.getASTContext().Diags.diagnose(effectsAttr->getLocation(), |
| 117 | + diag::warning_in_effects_attribute, "mismatching function effects"); |
| 118 | + } else { |
| 119 | + F->setEffectsKind(effectsAttr->getKind()); |
| 120 | + } |
170 | 121 | } |
171 | | - mod.getASTContext() |
172 | | - .Diags |
173 | | - .diagnose( |
174 | | - writeNoneEffect->getLocation(), |
175 | | - diag::fixit_attr_effects_consume_requires_explicit_releasenone) |
176 | | - .fixItInsertAfter(writeNoneEffect->getRange().End, |
177 | | - " @_effects(releasenone)"); |
178 | 122 | } |
179 | 123 | } |
180 | 124 |
|
|
0 commit comments