Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class CodegenContext {
if (freshNameIds.contains(fullName)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

now we don't need this if

val id = freshNameIds.getOrElse(fullName, 0)
val res = s"${fullName}_$id"
freshNameIds(fullName) = id + 1
res

val id = freshNameIds(fullName)
freshNameIds(fullName) = id + 1
s"$fullName$id"
s"${fullName}_$id"
} else {
freshNameIds += fullName -> 1
fullName

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the given name is something like name1_1, I think you can still produce non-unique variable name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd suggest something like s"${fullName}_0" at L581. It also solves the failed tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I am correct, does this still have a conflict between a_01 wth a_0$id where $id = 1?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't changed to s"${fullName}_$id"? So you will get a_0_1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it still has a problem. for sequence a_1, a, a, we have duplicated name a_1.

We can solve this problem by always adding the postfix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, doesn't it be

a_1 -> a_1_0
a -> a_0
a -> a_1

?

@kiszk kiszk Apr 17, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, sorry for my misunderstanding. To change line 581 would work well with unlikely-used char.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@viirya my comment was for the current code without your change.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,11 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
assert(!ctx.subExprEliminationExprs.contains(ref))
}
}

test("SPARK-23986: freshName can generate duplicated names") {
val ctx = new CodegenContext
val names = ctx.freshName("myName1") :: ctx.freshName("myName1") ::
ctx.freshName("myName11") :: Nil
assert(names.distinct.length == 3)
}
}