Skip to content

Commit 7693b05

Browse files
committed
Revert "Default to including columns by default"
This reverts commit 213cba2. Including columns by default make Ecto test suite consistently 10% slower and that's likely to replicate across the board.
1 parent 7181f2d commit 7693b05

File tree

6 files changed

+37
-41
lines changed

6 files changed

+37
-41
lines changed

lib/elixir/lib/code.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ defmodule Code do
820820
* `:column` - (since v1.11.0) the starting column of the string being parsed.
821821
Defaults to 1.
822822
823-
* `:columns` - when `false`, does not attach a `:column` key to the quoted
824-
metadata. Defaults to `true` since v1.13.0.
823+
* `:columns` - when `true`, attach a `:column` key to the quoted
824+
metadata. Defaults to `false`.
825825
826826
* `:unescape` (since v1.10.0) - when `false`, preserves escaped sequences.
827827
For example, `"null byte\\t\\x00"` will be kept as is instead of being

lib/elixir/src/elixir.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ handle_parsing_opts(File, Opts) ->
413413
false -> false
414414
end,
415415
TokenMetadata = lists:keyfind(token_metadata, 1, Opts) == {token_metadata, true},
416-
Columns = lists:keyfind(columns, 1, Opts) /= {columns, false},
416+
Columns = lists:keyfind(columns, 1, Opts) == {columns, true},
417417
put(elixir_parser_file, File),
418418
put(elixir_parser_columns, Columns),
419419
put(elixir_token_metadata, TokenMetadata),

lib/elixir/src/elixir_quote.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,13 @@ generated(Meta, #elixir_quote{generated=true}) -> [{generated, true} | Meta];
510510
generated(Meta, #elixir_quote{generated=false}) -> Meta.
511511

512512
keep(Meta, #elixir_quote{file=nil, line=Line}) ->
513-
line(keydelete(column, Meta), Line);
513+
line(Meta, Line);
514514
keep(Meta, #elixir_quote{file=File}) ->
515515
case lists:keytake(line, 1, Meta) of
516516
{value, {line, Line}, MetaNoLine} ->
517-
[{keep, {File, Line}} | keydelete(column, MetaNoLine)];
517+
[{keep, {File, Line}} | MetaNoLine];
518518
false ->
519-
[{keep, {File, 0}} | keydelete(column, Meta)]
519+
[{keep, {File, 0}} | Meta]
520520
end.
521521

522522
line(Meta, true) ->

lib/elixir/test/elixir/code_fragment_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ defmodule CodeFragmentTest do
803803
end
804804

805805
describe "container_cursor_to_quoted/2" do
806-
def s2q(arg, opts \\ [columns: false]), do: Code.string_to_quoted(arg, opts)
807-
def cc2q(arg, opts \\ [columns: false]), do: CF.container_cursor_to_quoted(arg, opts)
806+
def s2q(arg, opts \\ []), do: Code.string_to_quoted(arg, opts)
807+
def cc2q(arg, opts \\ []), do: CF.container_cursor_to_quoted(arg, opts)
808808

809809
test "completes terminators" do
810810
assert cc2q("(") == s2q("(__cursor__())")
@@ -913,7 +913,7 @@ defmodule CodeFragmentTest do
913913
assert cc2q("foo(", opts) == s2q("foo(__cursor__())", opts)
914914
assert cc2q("foo(123,", opts) == s2q("foo(123,__cursor__())", opts)
915915

916-
opts = [token_metadata: true, columns: false]
916+
opts = [token_metadata: true]
917917
assert cc2q("foo(", opts) == s2q("foo(__cursor__())", opts)
918918
assert cc2q("foo(123,", opts) == s2q("foo(123,__cursor__())", opts)
919919
end

lib/elixir/test/elixir/kernel/parser_test.exs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ defmodule Kernel.ParserTest do
5757

5858
describe "strings/sigils" do
5959
test "delimiter information for sigils is included" do
60-
string_to_quoted = &Code.string_to_quoted!(&1, token_metadata: false, columns: false)
60+
string_to_quoted = &Code.string_to_quoted!(&1, token_metadata: false)
6161

6262
assert parse!("~r/foo/") ==
6363
{:sigil_r, [delimiter: "/", line: 1], [{:<<>>, [line: 1], ["foo"]}, []]}
@@ -78,37 +78,39 @@ defmodule Kernel.ParserTest do
7878
end
7979

8080
test "sigil newlines" do
81-
assert {:sigil_s, _, [{:<<>>, _, ["here\ndoc"]}, []]} = parse!(~s|~s"here\ndoc"|)
81+
assert {:sigil_s, _, [{:<<>>, _, ["here\ndoc"]}, []]} =
82+
Code.string_to_quoted!(~s|~s"here\ndoc"|)
8283

83-
assert {:sigil_s, _, [{:<<>>, _, ["here\r\ndoc"]}, []]} = parse!(~s|~s"here\r\ndoc"|)
84+
assert {:sigil_s, _, [{:<<>>, _, ["here\r\ndoc"]}, []]} =
85+
Code.string_to_quoted!(~s|~s"here\r\ndoc"|)
8486
end
8587

8688
test "string newlines" do
87-
assert parse!(~s|"here\ndoc"|) == "here\ndoc"
88-
assert parse!(~s|"here\r\ndoc"|) == "here\r\ndoc"
89-
assert parse!(~s|"here\\\ndoc"|) == "heredoc"
90-
assert parse!(~s|"here\\\r\ndoc"|) == "heredoc"
89+
assert Code.string_to_quoted!(~s|"here\ndoc"|) == "here\ndoc"
90+
assert Code.string_to_quoted!(~s|"here\r\ndoc"|) == "here\r\ndoc"
91+
assert Code.string_to_quoted!(~s|"here\\\ndoc"|) == "heredoc"
92+
assert Code.string_to_quoted!(~s|"here\\\r\ndoc"|) == "heredoc"
9193
end
9294

9395
test "heredoc newlines" do
94-
assert parse!(~s|"""\nhere\ndoc\n"""|) == "here\ndoc\n"
95-
assert parse!(~s|"""\r\nhere\r\ndoc\r\n"""|) == "here\r\ndoc\r\n"
96-
assert parse!(~s| """\n here\n doc\n """|) == "here\ndoc\n"
97-
assert parse!(~s| """\r\n here\r\n doc\r\n """|) == "here\r\ndoc\r\n"
98-
assert parse!(~s|"""\nhere\\\ndoc\\\n"""|) == "heredoc"
99-
assert parse!(~s|"""\r\nhere\\\r\ndoc\\\r\n"""|) == "heredoc"
96+
assert Code.string_to_quoted!(~s|"""\nhere\ndoc\n"""|) == "here\ndoc\n"
97+
assert Code.string_to_quoted!(~s|"""\r\nhere\r\ndoc\r\n"""|) == "here\r\ndoc\r\n"
98+
assert Code.string_to_quoted!(~s| """\n here\n doc\n """|) == "here\ndoc\n"
99+
assert Code.string_to_quoted!(~s| """\r\n here\r\n doc\r\n """|) == "here\r\ndoc\r\n"
100+
assert Code.string_to_quoted!(~s|"""\nhere\\\ndoc\\\n"""|) == "heredoc"
101+
assert Code.string_to_quoted!(~s|"""\r\nhere\\\r\ndoc\\\r\n"""|) == "heredoc"
100102
end
101103

102104
test "heredoc indentation" do
103105
meta = [delimiter: "'''", line: 1]
104106
args = {:sigil_S, meta, [{:<<>>, [indentation: 2, line: 1], [" sigil heredoc\n"]}, []]}
105-
assert parse!("~S'''\n sigil heredoc\n '''") == args
107+
assert Code.string_to_quoted!("~S'''\n sigil heredoc\n '''") == args
106108
end
107109
end
108110

109111
describe "string_to_quoted/2" do
110112
test "converts strings to quoted expressions" do
111-
assert Code.string_to_quoted("1 + 2") == {:ok, {:+, [line: 1, column: 3], [1, 2]}}
113+
assert Code.string_to_quoted("1 + 2") == {:ok, {:+, [line: 1], [1, 2]}}
112114

113115
assert Code.string_to_quoted("a.1") ==
114116
{:error, {[line: 1, column: 3], "syntax error before: ", "\"1\""}}
@@ -148,7 +150,7 @@ defmodule Kernel.ParserTest do
148150
{:ok, {:my, "atom", ref}}
149151
end
150152

151-
assert {:ok, {{:my, "atom", ^ref}, [line: 1, column: 1], nil}} =
153+
assert {:ok, {{:my, "atom", ^ref}, [line: 1], nil}} =
152154
Code.string_to_quoted("there_is_no_such_var", static_atoms_encoder: encoder)
153155
end
154156

@@ -179,21 +181,20 @@ defmodule Kernel.ParserTest do
179181

180182
test "does not encode keywords" do
181183
encoder = fn atom, _meta -> raise "shouldn't be invoked for #{atom}" end
182-
string_to_quoted = &Code.string_to_quoted(&1, static_atoms_encoder: encoder, columns: false)
183184

184185
assert {:ok, {:fn, [line: 1], [{:->, [line: 1], [[1], 2]}]}} =
185-
string_to_quoted.("fn 1 -> 2 end")
186+
Code.string_to_quoted("fn 1 -> 2 end", static_atoms_encoder: encoder)
186187

187-
assert {:ok, {:or, [line: 1], [true, false]}} = string_to_quoted.("true or false")
188+
assert {:ok, {:or, [line: 1], [true, false]}} =
189+
Code.string_to_quoted("true or false", static_atoms_encoder: encoder)
188190

189191
encoder = fn atom, _meta -> {:ok, {:encoded, atom}} end
190-
string_to_quoted = &Code.string_to_quoted(&1, static_atoms_encoder: encoder, columns: false)
191192

192193
assert {:ok, [encoded: "true", encoded: "do", encoded: "and"]} =
193-
string_to_quoted.("[:true, :do, :and]")
194+
Code.string_to_quoted("[:true, :do, :and]", static_atoms_encoder: encoder)
194195

195196
assert {:ok, [{{:encoded, "do"}, 1}, {{:encoded, "true"}, 2}, {{:encoded, "end"}, 3}]} =
196-
string_to_quoted.("[do: 1, true: 2, end: 3]")
197+
Code.string_to_quoted("[do: 1, true: 2, end: 3]", static_atoms_encoder: encoder)
197198
end
198199

199200
test "returns errors on long atoms even when using static_atoms_encoder" do
@@ -303,7 +304,7 @@ defmodule Kernel.ParserTest do
303304
end
304305

305306
test "adds pairing information" do
306-
string_to_quoted = &Code.string_to_quoted!(&1, token_metadata: true, columns: false)
307+
string_to_quoted = &Code.string_to_quoted!(&1, token_metadata: true)
307308

308309
assert string_to_quoted.("foo") == {:foo, [line: 1], nil}
309310
assert string_to_quoted.("foo()") == {:foo, [closing: [line: 1], line: 1], []}
@@ -319,12 +320,7 @@ defmodule Kernel.ParserTest do
319320
end
320321

321322
test "with :literal_encoder" do
322-
opts = [
323-
literal_encoder: &{:ok, {:__block__, &2, [&1]}},
324-
token_metadata: true,
325-
columns: false
326-
]
327-
323+
opts = [literal_encoder: &{:ok, {:__block__, &2, [&1]}}, token_metadata: true]
328324
string_to_quoted = &Code.string_to_quoted!(&1, opts)
329325

330326
assert string_to_quoted.(~s("one")) == {:__block__, [delimiter: "\"", line: 1], ["one"]}
@@ -396,7 +392,7 @@ defmodule Kernel.ParserTest do
396392
end
397393

398394
test "adds metadata for the last alias segment" do
399-
string_to_quoted = &Code.string_to_quoted!(&1, token_metadata: true, columns: false)
395+
string_to_quoted = &Code.string_to_quoted!(&1, token_metadata: true)
400396

401397
assert string_to_quoted.("Foo") == {:__aliases__, [last: [line: 1], line: 1], [:Foo]}
402398

@@ -849,7 +845,7 @@ defmodule Kernel.ParserTest do
849845
end
850846
end
851847

852-
defp parse!(string), do: Code.string_to_quoted!(string, columns: false)
848+
defp parse!(string), do: Code.string_to_quoted!(string)
853849

854850
defp assert_token_missing(given_message, string) do
855851
assert_raise TokenMissingError, given_message, fn -> parse!(string) end

lib/elixir/test/elixir/kernel/quote_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ defmodule Kernel.QuoteTest do
235235
# The exception to this rule is an empty (). While empty expressions
236236
# are allowed, an empty () is ambiguous. We also can't use quote here,
237237
# since the formatter will rewrite (;) to something else.
238-
assert {:ok, {:__block__, [line: 1, column: 1], []}} = Code.string_to_quoted("(;)")
238+
assert {:ok, {:__block__, [line: 1], []}} = Code.string_to_quoted("(;)")
239239
end
240240

241241
test "bind quoted" do

0 commit comments

Comments
 (0)