|
1 | 1 | package dotty.tools.dotc
|
2 | 2 | package transform
|
3 | 3 |
|
| 4 | +import scala.language.postfixOps |
| 5 | + |
4 | 6 | import TreeTransforms._
|
5 | 7 | import core.Denotations._
|
6 | 8 | import core.SymDenotations._
|
@@ -53,19 +55,6 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
|
53 | 55 | translated.ensureConforms(tree.tpe)
|
54 | 56 | }
|
55 | 57 |
|
56 |
| - |
57 |
| - override def transformTry(tree: tpd.Try)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = { |
58 |
| - val selector = |
59 |
| - ctx.newSymbol(ctx.owner, ctx.freshName("ex").toTermName, Flags.Synthetic | Flags.Case, defn.ThrowableType, coord = tree.pos) |
60 |
| - val sel = Ident(selector.termRef).withPos(tree.pos) |
61 |
| - val rethrow = tpd.CaseDef(EmptyTree, EmptyTree, Throw(ref(selector))) |
62 |
| - val newCases = tpd.CaseDef( |
63 |
| - Bind(selector, Underscore(selector.info).withPos(tree.pos)), |
64 |
| - EmptyTree, |
65 |
| - transformMatch(tpd.Match(sel, tree.cases ::: rethrow :: Nil))) |
66 |
| - cpy.Try(tree)(tree.expr, newCases :: Nil, tree.finalizer) |
67 |
| - } |
68 |
| - |
69 | 58 | class Translator(implicit ctx: Context) {
|
70 | 59 |
|
71 | 60 | def translator = {
|
@@ -1264,27 +1253,6 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
|
1264 | 1253 | t
|
1265 | 1254 | }
|
1266 | 1255 |
|
1267 |
| - /** Is this pattern node a catch-all or type-test pattern? */ |
1268 |
| - def isCatchCase(cdef: CaseDef) = cdef match { |
1269 |
| - case CaseDef(Typed(Ident(nme.WILDCARD), tpt), EmptyTree, _) => |
1270 |
| - isSimpleThrowable(tpt.tpe) |
1271 |
| - case CaseDef(Bind(_, Typed(Ident(nme.WILDCARD), tpt)), EmptyTree, _) => |
1272 |
| - isSimpleThrowable(tpt.tpe) |
1273 |
| - case _ => |
1274 |
| - isDefaultCase(cdef) |
1275 |
| - } |
1276 |
| - |
1277 |
| - private def isSimpleThrowable(tp: Type)(implicit ctx: Context): Boolean = tp match { |
1278 |
| - case tp @ TypeRef(pre, _) => |
1279 |
| - val sym = tp.symbol |
1280 |
| - (pre == NoPrefix || pre.widen.typeSymbol.isStatic) && |
1281 |
| - (sym.derivesFrom(defn.ThrowableClass)) && /* bq */ !(sym is Flags.Trait) |
1282 |
| - case _ => |
1283 |
| - false |
1284 |
| - } |
1285 |
| - |
1286 |
| - |
1287 |
| - |
1288 | 1256 | /** Implement a pattern match by turning its cases (including the implicit failure case)
|
1289 | 1257 | * into the corresponding (monadic) extractors, and combining them with the `orElse` combinator.
|
1290 | 1258 | *
|
@@ -1335,46 +1303,6 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
|
1335 | 1303 | Block(List(ValDef(selectorSym, sel)), combined)
|
1336 | 1304 | }
|
1337 | 1305 |
|
1338 |
| - // return list of typed CaseDefs that are supported by the backend (typed/bind/wildcard) |
1339 |
| - // we don't have a global scrutinee -- the caught exception must be bound in each of the casedefs |
1340 |
| - // there's no need to check the scrutinee for null -- "throw null" becomes "throw new NullPointerException" |
1341 |
| - // try to simplify to a type-based switch, or fall back to a catch-all case that runs a normal pattern match |
1342 |
| - // unlike translateMatch, we type our result before returning it |
1343 |
| - /*def translateTry(caseDefs: List[CaseDef], pt: Type, pos: Position): List[CaseDef] = |
1344 |
| - // if they're already simple enough to be handled by the back-end, we're done |
1345 |
| - if (caseDefs forall isCatchCase) caseDefs |
1346 |
| - else { |
1347 |
| - val swatches = { // switch-catches |
1348 |
| - val bindersAndCases = caseDefs map { caseDef => |
1349 |
| - // generate a fresh symbol for each case, hoping we'll end up emitting a type-switch (we don't have a global scrut there) |
1350 |
| - // if we fail to emit a fine-grained switch, have to do translateCase again with a single scrutSym (TODO: uniformize substitution on treemakers so we can avoid this) |
1351 |
| - val caseScrutSym = freshSym(pos, pureType(defn.ThrowableType)) |
1352 |
| - (caseScrutSym, propagateSubstitution(translateCase(caseScrutSym, pt)(caseDef), EmptySubstitution)) |
1353 |
| - } |
1354 |
| -
|
1355 |
| - for(cases <- emitTypeSwitch(bindersAndCases, pt).toList |
1356 |
| - if cases forall isCatchCase; // must check again, since it's not guaranteed -- TODO: can we eliminate this? e.g., a type test could test for a trait or a non-trivial prefix, which are not handled by the back-end |
1357 |
| - cse <- cases) yield /*fixerUpper(matchOwner, pos)*/(cse).asInstanceOf[CaseDef] |
1358 |
| - } |
1359 |
| -
|
1360 |
| - val catches = if (swatches.nonEmpty) swatches else { |
1361 |
| - val scrutSym = freshSym(pos, pureType(defn.ThrowableType)) |
1362 |
| - val casesNoSubstOnly = caseDefs map { caseDef => (propagateSubstitution(translateCase(scrutSym, pt)(caseDef), EmptySubstitution))} |
1363 |
| -
|
1364 |
| - val exSym = freshSym(pos, pureType(defn.ThrowableType), "ex") |
1365 |
| -
|
1366 |
| - List( |
1367 |
| - CaseDef( |
1368 |
| - Bind(exSym, Ident(??? /*nme.WILDCARD*/)), // TODO: does this need fixing upping? |
1369 |
| - EmptyTree, |
1370 |
| - combineCasesNoSubstOnly(ref(exSym), scrutSym, casesNoSubstOnly, pt, matchOwner, Some((scrut: Symbol) => Throw(ref(exSym)))) |
1371 |
| - ) |
1372 |
| - ) |
1373 |
| - } |
1374 |
| -
|
1375 |
| - /*typer.typedCases(*/catches/*, defn.ThrowableType, WildcardType)*/ |
1376 |
| - }*/ |
1377 |
| - |
1378 | 1306 | /** The translation of `pat if guard => body` has two aspects:
|
1379 | 1307 | * 1) the substitution due to the variables bound by patterns
|
1380 | 1308 | * 2) the combination of the extractor calls using `flatMap`.
|
|
0 commit comments