[m-rev.] for review: Delete deprecated substring predicates and functions.
Peter Wang
novalazy at gmail.com
Thu Nov 7 15:21:16 AEDT 2019
library/string.m:
Delete long-deprecated substring/3 function and substring/4 predicate.
The newly introduced `string_piece' type has a substring/3 data
constructor which takes (start, end) offsets into the base string,
whereas the function and predicate take (start, count) arguments.
To reduce potential confusion, delete the deprecated function and
predicate.
Delete other deprecated substring predicates and functions as well.
tests/general/Mercury.options:
tests/general/string_foldl_substring.exp:
tests/general/string_foldl_substring.m:
tests/general/string_foldr_substring.exp:
tests/general/string_foldr_substring.m:
tests/hard_coded/Mercury.options:
tests/hard_coded/string_substring.m:
Delete tests for deprecated predicates.
tests/tabling/mercury_java_parser_dead_proc_elim_bug.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m:
tests/valid/mercury_java_parser_follow_code_bug.m:
Replace calls to unsafe_substring with unsafe_between.
NEWS:
Announce the changes.
---
NEWS | 14 ++
library/string.m | 122 ------------------
tests/general/Mercury.options | 4 -
tests/general/string_foldl_substring.exp | 8 --
tests/general/string_foldl_substring.m | 24 ----
tests/general/string_foldr_substring.exp | 8 --
tests/general/string_foldr_substring.m | 24 ----
tests/hard_coded/Mercury.options | 1 -
tests/hard_coded/string_substring.m | 16 ---
.../mercury_java_parser_dead_proc_elim_bug.m | 2 +-
.../mercury_java_parser_dead_proc_elim_bug2.m | 2 +-
.../mercury_java_parser_follow_code_bug.m | 2 +-
12 files changed, 17 insertions(+), 210 deletions(-)
diff --git a/NEWS b/NEWS
index 80e4504d3..60c5deb16 100644
--- a/NEWS
+++ b/NEWS
@@ -443,6 +443,20 @@ Changes to the Mercury standard library:
- prefix(in, out)
- suffix(in, out)
+ The following predicates and functions in the string module have been
+ removed:
+
+ - substring/3
+ - substring/4
+ - unsafe_substring/3
+ - unsafe_substring/4
+ - foldl_substring/5
+ - foldl_substring/6
+ - foldl2_substring/8
+ - foldl2_substring/8
+ - foldr_substring/5
+ - foldr_substring/6
+
* The following predicates have been added to the map module:
- foldl5/12
diff --git a/library/string.m b/library/string.m
index ebcbc8a97..5f10270fe 100644
--- a/library/string.m
+++ b/library/string.m
@@ -809,14 +809,6 @@
:- func between(string::in, int::in, int::in) = (string::uo) is det.
:- pred between(string::in, int::in, int::in, string::uo) is det.
- % substring(String, Start, Count, Substring):
- % Please use `between' instead.
- %
-:- pragma obsolete(substring/3).
-:- pragma obsolete(substring/4).
-:- func substring(string::in, int::in, int::in) = (string::uo) is det.
-:- pred substring(string::in, int::in, int::in, string::uo) is det.
-
% between_codepoints(String, Start, End, Substring):
%
% `Substring' is the part of `String' between the code point positions
@@ -856,14 +848,6 @@
:- func unsafe_between(string::in, int::in, int::in) = (string::uo) is det.
:- pred unsafe_between(string::in, int::in, int::in, string::uo) is det.
- % unsafe_substring(String, Start, Count, Substring):
- % Please use unsafe_between instead.
- %
-:- pragma obsolete(unsafe_substring/3).
-:- pragma obsolete(unsafe_substring/4).
-:- func unsafe_substring(string::in, int::in, int::in) = (string::uo) is det.
-:- pred unsafe_substring(string::in, int::in, int::in, string::uo) is det.
-
% words_separator(SepP, String) returns the list of non-empty
% substrings of String (in first to last order) that are delimited
% by non-empty sequences of characters (code points) matched by SepP.
@@ -1227,43 +1211,6 @@
:- mode foldl2_between(pred(in, in, out, in, out) is multi,
in, in, in, in, out, in, out) is multi.
- % foldl_substring(Closure, String, Start, Count, !Acc)
- % Please use foldl_between instead.
- %
-:- pragma obsolete(foldl_substring/5).
-:- pragma obsolete(foldl_substring/6).
-:- func foldl_substring(func(char, A) = A, string, int, int, A) = A.
-:- pred foldl_substring(pred(char, A, A), string, int, int, A, A).
-:- mode foldl_substring(pred(in, in, out) is det, in, in, in,
- in, out) is det.
-:- mode foldl_substring(pred(in, di, uo) is det, in, in, in,
- di, uo) is det.
-:- mode foldl_substring(pred(in, in, out) is semidet, in, in, in,
- in, out) is semidet.
-:- mode foldl_substring(pred(in, in, out) is nondet, in, in, in,
- in, out) is nondet.
-:- mode foldl_substring(pred(in, in, out) is multi, in, in, in,
- in, out) is multi.
-
- % foldl2_substring(Closure, String, Start, Count, !Acc1, !Acc2)
- % Please use foldl2_between instead.
- %
-:- pragma obsolete(foldl2_substring/8).
-:- pred foldl2_substring(pred(char, A, A, B, B),
- string, int, int, A, A, B, B).
-:- mode foldl2_substring(pred(in, di, uo, di, uo) is det,
- in, in, in, di, uo, di, uo) is det.
-:- mode foldl2_substring(pred(in, in, out, di, uo) is det,
- in, in, in, in, out, di, uo) is det.
-:- mode foldl2_substring(pred(in, in, out, in, out) is det,
- in, in, in, in, out, in, out) is det.
-:- mode foldl2_substring(pred(in, in, out, in, out) is semidet,
- in, in, in, in, out, in, out) is semidet.
-:- mode foldl2_substring(pred(in, in, out, in, out) is nondet,
- in, in, in, in, out, in, out) is nondet.
-:- mode foldl2_substring(pred(in, in, out, in, out) is multi,
- in, in, in, in, out, in, out) is multi.
-
% foldr(Closure, String, !Acc):
% As foldl/4, except that processing proceeds right-to-left.
%
@@ -1294,24 +1241,6 @@
:- mode foldr_between(pred(in, in, out) is multi, in, in, in,
in, out) is multi.
- % foldr_substring(Closure, String, Start, Count, !Acc)
- % Please use foldr_between instead.
- %
-:- pragma obsolete(foldr_substring/5).
-:- pragma obsolete(foldr_substring/6).
-:- func foldr_substring(func(char, T) = T, string, int, int, T) = T.
-:- pred foldr_substring(pred(char, T, T), string, int, int, T, T).
-:- mode foldr_substring(pred(in, in, out) is det, in, in, in,
- in, out) is det.
-:- mode foldr_substring(pred(in, di, uo) is det, in, in, in,
- di, uo) is det.
-:- mode foldr_substring(pred(in, in, out) is semidet, in, in, in,
- in, out) is semidet.
-:- mode foldr_substring(pred(in, in, out) is nondet, in, in, in,
- in, out) is nondet.
-:- mode foldr_substring(pred(in, in, out) is multi, in, in, in,
- in, out) is multi.
-
%---------------------------------------------------------------------------%
%
% Formatting tables.
@@ -4361,30 +4290,6 @@ between(Str, Start, End, SubStr) :-
%---------------------%
-substring(Str, Start, Count) = SubString :-
- substring(Str, Start, Count, SubString).
-
-substring(Str, Start, Count, SubString) :-
- convert_endpoints(Start, Count, ClampStart, ClampEnd),
- between(Str, ClampStart, ClampEnd, SubString).
-
-:- pred convert_endpoints(int::in, int::in, int::out, int::out) is det.
-
-convert_endpoints(Start, Count, ClampStart, ClampEnd) :-
- ClampStart = int.max(0, Start),
- ( if Count =< 0 then
- ClampEnd = ClampStart
- else
- % Check for overflow.
- ( if ClampStart > max_int - Count then
- ClampEnd = max_int
- else
- ClampEnd = ClampStart + Count
- )
- ).
-
-%---------------------%
-
between_codepoints(Str, Start, End) = SubString :-
between_codepoints(Str, Start, End, SubString).
@@ -4443,12 +4348,6 @@ unsafe_between(Str, Start, End) = SubString :-
<< _:Start/binary, SubString:Count/binary, _/binary >> = Str
").
-unsafe_substring(Str, Start, Count) = SubString :-
- unsafe_between(Str, Start, Start + Count) = SubString.
-
-unsafe_substring(Str, Start, Count, SubString) :-
- unsafe_between(Str, Start, Start + Count, SubString).
-
%---------------------%
words_separator(SepP, String) = Words :-
@@ -5207,19 +5106,6 @@ foldl2_between_2(Closure, String, I, End, !Acc1, !Acc2) :-
true
).
-foldl_substring(F, String, Start, Count, Acc0) = Acc :-
- convert_endpoints(Start, Count, ClampStart, ClampEnd),
- Acc = foldl_between(F, String, ClampStart, ClampEnd, Acc0).
-
-foldl_substring(Closure, String, Start, Count, !Acc) :-
- convert_endpoints(Start, Count, ClampStart, ClampEnd),
- foldl_between(Closure, String, ClampStart, ClampEnd, !Acc).
-
-foldl2_substring(Closure, String, Start, Count, !Acc1, !Acc2) :-
- convert_endpoints(Start, Count, ClampStart, ClampEnd),
- foldl2_between(Closure, String, ClampStart, ClampEnd,
- !Acc1, !Acc2).
-
%---------------------%
foldr(F, String, Acc0) = Acc :-
@@ -5262,14 +5148,6 @@ foldr_between_2(Closure, String, Start, I, !Acc) :-
true
).
-foldr_substring(F, String, Start, Count, Acc0) = Acc :-
- convert_endpoints(Start, Count, ClampStart, ClampEnd),
- Acc = foldr_between(F, String, ClampStart, ClampEnd, Acc0).
-
-foldr_substring(Closure, String, Start, Count, !Acc) :-
- convert_endpoints(Start, Count, ClampStart, ClampEnd),
- foldr_between(Closure, String, ClampStart, ClampEnd, !Acc).
-
%---------------------------------------------------------------------------%
%
% Formatting tables.
diff --git a/tests/general/Mercury.options b/tests/general/Mercury.options
index b0493451b..5f59e82e3 100644
--- a/tests/general/Mercury.options
+++ b/tests/general/Mercury.options
@@ -11,10 +11,6 @@ MCFLAGS-ho_spec_branch_bug = --optimize-higher-order
MCFLAGS-intermod_type = --intermodule-optimization
MCFLAGS-intermod_type2 = --intermodule-optimization
-# These test cases also check obsolete procedures.
-MCFLAGS-string_foldl_substring = --no-warn-obsolete
-MCFLAGS-string_foldr_substring = --no-warn-obsolete
-
# In grade `none' with options `-O1 --opt-space' on kryten
# (a sparc-sun-solaris2.5 system), string_test needs to be linked
# with `--no-strip', otherwise it gets a seg fault.
diff --git a/tests/general/string_foldl_substring.exp b/tests/general/string_foldl_substring.exp
index 1bec99d00..0e52b14af 100644
--- a/tests/general/string_foldl_substring.exp
+++ b/tests/general/string_foldl_substring.exp
@@ -6,11 +6,3 @@ rev("Hello, World!", -5, 50) = "!dlroW ,olleH"
rev("Hello, World!", 7, 0) = ""
rev("Hello, World!", 7, 12) = "dlroW"
rev("Hello, World!", 50, 10) = ""
-rev_old("Hello, World!", 0, 5) = "olleH"
-rev_old("Hello, World!", 0, 50) = "!dlroW ,olleH"
-rev_old("Hello, World!", 0, -5) = ""
-rev_old("Hello, World!", -5, 12) = "dlroW ,olleH"
-rev_old("Hello, World!", -5, 50) = "!dlroW ,olleH"
-rev_old("Hello, World!", 7, 0) = ""
-rev_old("Hello, World!", 7, 12) = "!dlroW"
-rev_old("Hello, World!", 50, 10) = ""
diff --git a/tests/general/string_foldl_substring.m b/tests/general/string_foldl_substring.m
index f246f867e..4344c62a8 100644
--- a/tests/general/string_foldl_substring.m
+++ b/tests/general/string_foldl_substring.m
@@ -45,25 +45,6 @@ main(!IO) :-
"\"\nrev(\"Hello, World!\", 50, 10) = \"",
rev("Hello, World!", 50, 10),
"\"\n"
- ], !IO),
- io__write_strings([
- "rev_old(\"Hello, World!\", 0, 5) = \"",
- rev_old("Hello, World!", 0, 5),
- "\"\nrev_old(\"Hello, World!\", 0, 50) = \"",
- rev_old("Hello, World!", 0, 50),
- "\"\nrev_old(\"Hello, World!\", 0, -5) = \"",
- rev_old("Hello, World!", 0, -5),
- "\"\nrev_old(\"Hello, World!\", -5, 12) = \"",
- rev_old("Hello, World!", -5, 12),
- "\"\nrev_old(\"Hello, World!\", -5, 50) = \"",
- rev_old("Hello, World!", -5, 50),
- "\"\nrev_old(\"Hello, World!\", 7, 0) = \"",
- rev_old("Hello, World!", 7, 0),
- "\"\nrev_old(\"Hello, World!\", 7, 12) = \"",
- rev_old("Hello, World!", 7, 12),
- "\"\nrev_old(\"Hello, World!\", 50, 10) = \"",
- rev_old("Hello, World!", 50, 10),
- "\"\n"
], !IO).
:- func rev(string, int, int) = string.
@@ -71,10 +52,5 @@ main(!IO) :-
rev(S, I, N) =
from_char_list(foldl_between(func(X, Xs) = [X | Xs], S, I, N, [])).
-:- func rev_old(string, int, int) = string.
-
-rev_old(S, I, N) =
- from_char_list(foldl_substring(func(X, Xs) = [X | Xs], S, I, N, [])).
-
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
diff --git a/tests/general/string_foldr_substring.exp b/tests/general/string_foldr_substring.exp
index 63cfeca5b..aea27e545 100644
--- a/tests/general/string_foldr_substring.exp
+++ b/tests/general/string_foldr_substring.exp
@@ -6,11 +6,3 @@ sub("Hello, World!", -5, 50) = "Hello, World!"
sub("Hello, World!", 7, 0) = ""
sub("Hello, World!", 7, 12) = "World"
sub("Hello, World!", 50, 10) = ""
-sub_old("Hello, World!", 0, 5) = "Hello"
-sub_old("Hello, World!", 0, 50) = "Hello, World!"
-sub_old("Hello, World!", 0, -5) = ""
-sub_old("Hello, World!", -5, 12) = "Hello, World"
-sub_old("Hello, World!", -5, 50) = "Hello, World!"
-sub_old("Hello, World!", 7, 0) = ""
-sub_old("Hello, World!", 7, 12) = "World!"
-sub_old("Hello, World!", 50, 10) = ""
diff --git a/tests/general/string_foldr_substring.m b/tests/general/string_foldr_substring.m
index 6683def07..0c18deaa1 100644
--- a/tests/general/string_foldr_substring.m
+++ b/tests/general/string_foldr_substring.m
@@ -45,25 +45,6 @@ main(!IO) :-
"\"\nsub(\"Hello, World!\", 50, 10) = \"",
sub("Hello, World!", 50, 10),
"\"\n"
- ], !IO),
- io__write_strings([
- "sub_old(\"Hello, World!\", 0, 5) = \"",
- sub_old("Hello, World!", 0, 5),
- "\"\nsub_old(\"Hello, World!\", 0, 50) = \"",
- sub_old("Hello, World!", 0, 50),
- "\"\nsub_old(\"Hello, World!\", 0, -5) = \"",
- sub_old("Hello, World!", 0, -5),
- "\"\nsub_old(\"Hello, World!\", -5, 12) = \"",
- sub_old("Hello, World!", -5, 12),
- "\"\nsub_old(\"Hello, World!\", -5, 50) = \"",
- sub_old("Hello, World!", -5, 50),
- "\"\nsub_old(\"Hello, World!\", 7, 0) = \"",
- sub_old("Hello, World!", 7, 0),
- "\"\nsub_old(\"Hello, World!\", 7, 12) = \"",
- sub_old("Hello, World!", 7, 12),
- "\"\nsub_old(\"Hello, World!\", 50, 10) = \"",
- sub_old("Hello, World!", 50, 10),
- "\"\n"
], !IO).
:- func sub(string, int, int) = string.
@@ -71,10 +52,5 @@ main(!IO) :-
sub(S, I, N) =
from_char_list(foldr_between(func(X, Xs) = [X | Xs], S, I, N, [])).
-:- func sub_old(string, int, int) = string.
-
-sub_old(S, I, N) =
- from_char_list(foldr_substring(func(X, Xs) = [X | Xs], S, I, N, [])).
-
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
diff --git a/tests/hard_coded/Mercury.options b/tests/hard_coded/Mercury.options
index 44bcda104..1b3459638 100644
--- a/tests/hard_coded/Mercury.options
+++ b/tests/hard_coded/Mercury.options
@@ -75,7 +75,6 @@ MCFLAGS-sharing_comb = --ctgc --structure-sharing-widening 2
MCFLAGS-shift_test = --no-warn-obsolete
MCFLAGS-simplify_multi_arm_switch = -O3
MCFLAGS-spawn_native = --no-ansi-c
-MCFLAGS-string_substring = --no-warn-obsolete
MCFLAGS-tail-rec-scc = --inine-linear-tail-rec-sccs
MCFLAGS-term_io_test = --no-warn-unresolved-polymorphism
MCFLAGS-test_imported_no_tag = --no-warn-interface-imports
diff --git a/tests/hard_coded/string_substring.m b/tests/hard_coded/string_substring.m
index 48ab5066c..df0bfeb3c 100644
--- a/tests/hard_coded/string_substring.m
+++ b/tests/hard_coded/string_substring.m
@@ -18,22 +18,6 @@
main(!IO) :-
(
- string.substring("cat", -1, max_int, "cat"),
- string.substring("cat", 0, max_int, "cat"),
- string.substring("cat", 1, max_int, "at"),
- string.substring("cat", 2, max_int, "t"),
- string.substring("cat", 3, max_int, ""),
- string.substring("cat", 4, max_int, ""),
- string.substring("cat", 0, 0, ""),
- string.substring("cat", 0, 1, "c"),
- string.substring("cat", 0, 2, "ca"),
- string.substring("cat", 0, 3, "cat"),
- string.substring("cat", 1, -1, ""),
- string.substring("cat", 1, 0, ""),
- string.substring("cat", 1, 1, "a"),
- string.substring("cat", 1, 2, "at"),
- string.substring("cat", 1, 3, "at"),
-
string.between("cat", -1, max_int, "cat"),
string.between("cat", 0, max_int, "cat"),
string.between("cat", 1, max_int, "at"),
diff --git a/tests/tabling/mercury_java_parser_dead_proc_elim_bug.m b/tests/tabling/mercury_java_parser_dead_proc_elim_bug.m
index da3c0b6f7..317c6af61 100644
--- a/tests/tabling/mercury_java_parser_dead_proc_elim_bug.m
+++ b/tests/tabling/mercury_java_parser_dead_proc_elim_bug.m
@@ -166,7 +166,7 @@ input_substring(Start, End, Substring, Offset, Offset) :-
promise_pure (
semipure input_string_and_length(Str, Length),
End =< Length,
- Substring = unsafe_substring(Str, Start, End - Start)
+ Substring = unsafe_between(Str, Start, End)
).
%---------------------------------------------------------------------------%
diff --git a/tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m b/tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m
index 6e2cdd2c8..d72d07b49 100644
--- a/tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m
+++ b/tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m
@@ -163,7 +163,7 @@ input_substring(Start, End, Substring, Offset, Offset) :-
promise_pure (
semipure input_string_and_length(Str, Length),
End =< Length,
- Substring = unsafe_substring(Str, Start, End - Start)
+ Substring = unsafe_between(Str, Start, End)
).
%---------------------------------------------------------------------------%
diff --git a/tests/valid/mercury_java_parser_follow_code_bug.m b/tests/valid/mercury_java_parser_follow_code_bug.m
index bff202b97..96d26014e 100644
--- a/tests/valid/mercury_java_parser_follow_code_bug.m
+++ b/tests/valid/mercury_java_parser_follow_code_bug.m
@@ -155,7 +155,7 @@ char(Char, Offset, Offset + 1) :-
input_substring(Start, End, Substring, Offset, Offset) :-
semipure input_string_and_length(Str, Length),
End =< Length,
- Substring = unsafe_substring(Str, Start, End - Start).
+ Substring = unsafe_between(Str, Start, End).
:- pred match_string(string::in, int::in, int::out) is semidet.
:- pragma promise_pure(match_string/3).
--
2.23.0
More information about the reviews
mailing list